Pyinfra – automate infrastructure super fast at scale
pyinfra.com
pyinfra.com
Is there any way to attach the deployement scenario in a Python object ?
All the examples I see are global functions called at a root of a module.
How do I make a scenario pluggable? Reusable? Introspectable?
It is possible to use pyinfra as a Python API, but this is not currently officially supported/may not follow semver, example: https://github.com/Fizzadar/pyinfra/blob/master/examples/api....
> How do I make a scenario pluggable? Reusable? Introspectable?
pyinfra comes with builtin support for packaging "deploys" as Python packages, see: https://pyinfra.readthedocs.io/en/v0.14.5/api/deploys.html, an example: https://github.com/Fizzadar/pyinfra-docker.
The use of Python for the inventory + deploy code makes it possible to integrate pyinfra with almost any external tool, without specific support in pyinfra (that's the theory, at least!).
How is it executing remote commands ?
Is it uploading a script like ansible, or just executing remote commands ? The latter seems to be the case glancing at the source code, nice one !
Seems like a much more modern Ansible to me, more precise but more targeting Python users instead of trying to attract non-coders too, it's very promising. I wish I had found your project before I started my own too, it's shitty compared to yours but i'll swallow my shame and share it with you just in case you find an idea that you like yourlabs.io/oss/shlax
Ansible is a great system, with a terrible DSL.
YAML is not a programming language, and deployment is not a toy task. You need power.
The result is that ansible has pushed a markup language to its limit, then pushed the templating engine used in it to its limit too. Then used a bunch of duck tape + conventions to glue everything and ended up with 10% of an unclean verbose unexpressive real programming language with ridiculous limited tooling, testability and had to document + support it.
As with most DSL.
For what? For the quest of having something "declarative", and that any language could read.
Well you can have declarative API written in any language, and nobody except ansible ever read playbooks.
In the end, it's just a big weight at the ankle. I never ever used it and though, "damn, what a pleasant tech choice, I'm happy they didn't directly expose the API through Python".
It's the same reason I use "nox" and not "tox", or "doit" and not "make". DSL really seem like a great idea, but they fail most of the time. There is a reason only few of them - like SQL, CSS or regex patterns - became a success. 99% of the time, what you need is a good lib, with a well designed API. For the 0.9% of the time you do need multi-language communication, you may implement RPC. Then, only for the 0.01% case should you really consider a DSL.
But we geek love to create DSL. They are fun to write! They are so elegant in tutorials!
Is Pyinfra doing better? I don't know, but I'm sure to give it a try. I really, really want to leave ansible behind, but fabric 2 is not high level or declarative enough.
That said, pyinfra seems to be making the same mistakes (being a tool instead of a library, prescribing a folder structure, not letting me create my own abstractions), so you are right that it provides no advantage over Ansible.
You can use python logic to compose your deployment scenario, use imports to reuse features, package modules the same way, etc. The whole ecosystem is also at your disposal, be it libraries, IDE support, linters, formatters, debuggers and so on.
It doesn't need to reinvent the wheel, and you don't need to learn a new syntax.
I would call that a win.
Now, is pyinfra well designed enough to be practical in production, that's another matter that needs testing.
But honestly pyinfra seems like the clean Ansible rewrite for people who like both devops and python programing, pyinfra looks like the next major version of Ansible.
One major benefit over ansible is that you only need a posix shell on the remote side, instead of a compatible version of python and possibly some specific libraries. Which is a also a major downside if you want to manage systems that don't have a posix shell.
I don't even know where to begin explaining how frustrating Ansible is. Over time they've compounded one bad design decision on top of another, while never adding any actually useful functionality to be able to troubleshoot or iterate on the many random failures. They also don't provide guidance on how "if you use feature X, features a, b, c, d, and e will not work correctly". Finding a working example of core functionality, like an AWS inventory plugin, requires you to dig through all of the code and scour the internet and experiment for a day before you have a simple working configuration. The more features you use, the more fragile and shitty it becomes, to the point that nobody wants to actually change any roles or playbooks because deployments might stop working and it'll take you two days to figure out how to make them work again in Ansible's bass-ackwards design. And of course, it's Python, so you have to teach all your users how to use virtualenvs, freeze deps, and run it with Docker, or you'll constantly hear "it didn't run correctly for me".
Documentation is middling at best imo and it just feels hacked together.
It seems like a tool which was written by an ops person (as in hacked together) for ops people (who don't mind stuff being hacked together), specifically for replacing manually distributed cryptic bash files. It's an improvement over that, for sure, but that's it.
Isn’t the point of Docker that not everyone has to know the virtual envs, etc?
I hate technology.
And then when you get those errors you need to understand what the object is and now you're running the debug on a ton of variables, some of which you first need to set facts on, then others you don't know what are available.
IMO the biggest problem with Ansible is that it feels like it was designed with a really good idea in mind, and then extended and modified by a bunch of different teams who had their own ideas. Which is fine if you've been paying attention, but explaining it all to someone new can be overwhelming.
if your DSL gets to that point sometimes it's better to rewrite as a library.
seems like pyinfra is OS agnostic.
from pyinfra.modules import apt
apt.packages(
{'Install iftop'},
'iftop',
sudo=True,
)
And search over docs doesn't produce results for Windows/MacOS* https://pyinfra.readthedocs.io/en/v0.14.5/search.html?q=wind...
* https://pyinfra.readthedocs.io/en/v0.14.5/search.html?q=maco...
- SaltStack [2], which has a broad range of execution and state modules, uses by default a "Master/Minion" architecture, but can be used push-based through "salt-ssh" [3] as well
- POP/Idem [4] - which originates in the concept of idempotent SaltStack states, but exposes this functionality as Python code and uses the POP paradigm [5] coined by SaltStack's founder Thomas Hatch. A lot of SaltStack itself will quite likely move towards this architecture in the foreseeable future as well
[1] https://www.pulumi.com/docs/ [2] https://github.com/saltstack/salt/ [3] https://docs.saltstack.com/en/latest/topics/ssh/index.html [4] https://gitlab.com/saltstack/pop/idem [5] https://pop.readthedocs.io
And well, start with a backup and be careful when you're working in production but that's common sense right ?
There is no relationship between pyinfra, pipenv and pip.
There is not even a relationship between pip and pipenv, they are completly different teams.
In fact, none of those projects are maintained by the Python core team or part of the Python project. Not even pip, which is separated from Python and provided using get-pip.py at install.