Top
Best
New

Posted by wowi42 5 days ago

PyInfra 3.8.0(github.com)
306 points | 107 commentspage 3
odie5533 5 days ago|
Does it have an equivalent to konstruktoid's hardening Ansible playbook?
wowi42 5 days ago|
we could put it on our roadmap of examples :-)
mark_l_watson 5 days ago||
That would have been very useful to me, before I retired! That said, I only run the Hermes Agent on leased VPSs and PyInfra might be a cool and easy to access Hermes - I need to think about that.
dist-epoch 5 days ago|
I tried something like that, using PyInfra to setup VMs for agent. But gave up, too much complexity for too little gain. Just ask the agent to create a small install script.
reddit_clone 5 days ago||
Does this abstract over the package management systems (apt, yum , apk etc.)? Or do we still have to write distro specific install commands?
firesteelrain 5 days ago||
We created something similar to PyInfra at work back in 2017. I wonder if we would have used it back then if it existed.
sgarland 5 days ago||
Never heard of this before. In looking through docs, honestly it looks like Ansible, but for people who don’t know Ansible, and with way more footguns. The fact that you can import any existing Python library means you’re now relying on those libraries to not introduce bugs, or throw an exception in the middle of an operation, etc.

I despise YAML, but I can appreciate that it makes it harder to introduce imperative logic, and it forces you to stay on the paved path - which is very well-tested.

roryirvine 5 days ago||
That was why any moderate to large Chef installation always turned out to be such a nightmare in practice - it was so easy to break out of the DSL, so people ended up swaddling it in impenetrable, unmaintainable spaghetti code. Ansible was a real breath of fresh air when it first came along!

This is just the pendulum swinging back again, and at least Python tends to be a little less "clever" (and therefore less write-only) than Ruby.

It seems to me that infra management is inherently suited to declarative logic. I'm pragmatic enough to understand why SWEs with little infra experience might prefer an imperative approach, but I tend to think you should pick one or the other and stick to it. In my experience, hybrid systems end up combining the worst aspects of both.

sgarland 5 days ago||
> It seems to me that infra management is inherently suited to declarative logic. I'm pragmatic enough to understand why SWEs with little infra experience might prefer an imperative approach, but I tend to think you should pick one or the other and stick to it.

Yep. IMO, imperative is definitely easier to reason about, and it’s what most programming languages are designed around, but it is absolutely the wrong approach for infrastructure. There are too many things that can go wrong that you may or may not have designed for. Declarative _is_ the state.

wowi42 5 days ago|||
Hey, fair pushback, let me try to clear up a couple of points because I think there are some genuine misconceptions worth untangling.

On footguns. Totally hear you that "Python lets you do anything" feels like a footgun. The flip side that I think gets missed: because it is real Python, you can actually test it. Pytest, mypy, ruff, jump-to-definition, refactor-rename, all of it just works. Unit-testing a 400-line YAML role with nested Jinja conditionals is genuinely hard, and that gap is what pushed me toward PyInfra in the first place.

On "importing Python libraries introduces bugs". This one I think is worth a closer look, because the mechanics are not what they appear. PyInfra does not run Python on your servers. It runs Python on your control node to plan the change, then transpiles each operation to plain POSIX shell and pipes that over SSH. If you run with `-vvv` you can see it: `sh -c '...'` and nothing else on the wire. The target needs zero Python, zero agent, zero runtime. So whatever library you imported into your deploy script ran locally, produced a string of shell, and that string is what touches the box. A bug in some PyPI dependency cannot throw mid-operation on the host, because there is no Python on the host to throw it. Worth noting that Ansible, by contrast, ships a Python interpreter and module code to the target for most tasks, so if anything the library exposure on the executing side is larger there, not smaller.

On the control node, sure, you have dependencies, same as Ansible has Jinja2, PyYAML, paramiko, cryptography, and a long tail of Galaxy collections of varying quality. PyInfra has a stable API, solid test coverage, idempotent operations, and a real two-phase model (gather facts, then apply) so the apply phase is deterministic generated shell rather than arbitrary code running on the box.

On YAML keeping you on the paved path. I really wanted this to be true for years, honestly. In practice, the moment you need a conditional you end up writing `{% if %}` inside a quoted string inside a map inside a list inside a role, with no type system, no debugger, and a few sharp edges in the parser (`no` as boolean, leading zeros as octal in YAML 1.1, tab/space mixing failing without a useful pointer). And the escape hatch when Jinja-in-YAML cannot express what you need is... writing a custom Python module. So you end up writing Python anyway, just with worse tooling around it.

The way I would put it: PyInfra is Python where Python helps (writing, testing, planning) and shell where shell belongs (executing on the host). Happy to dig into any specific footgun you have run into though, those are usually the most useful conversations.

bmurphy1976 4 days ago||
You can build spaghetti in anything and that definitely includes Ansible.
sgarland 2 days ago||
Sure - but it’s easier to spot and squash. Banning the use of the command and shell modules eliminates a majority of spaghetti / idempotency footguns.
jlintz 4 days ago||
nice project, reminds me a lot of Fabric but a bit more refined
hacker161 5 days ago||
See lots of comparisons to Ansible but Chef/puppet (both of which have agent-less modes) in Python instead of Ruby is what immediately came to mind. I guess Salt as well technically.
ohdeardear 5 days ago||
[dead]
gandreani 5 days ago|
There's a video!

I can't get over the fact of how suspicious he looks while doing it. And doesn't even cover his face. Crazyness

https://x.com/porqueTTarg/status/2047652413306277970 https://xcancel.com/porqueTTarg/status/2047652413306277970

alanwreath 5 days ago|
This is spam - btw this is the first spam I have ever come across on hacker news
akshaykarthik 5 days ago|||
I think this was likely an attempted response to https://news.ycombinator.com/item?id=48008326
alanwreath 5 days ago||
Yes - that’s got to be it.
electroly 5 days ago||||
FWIW, if you turn on "showdead", there is a ton of spam on HN. The mods are just really good.
JSR_FDED 5 days ago||
Showdead is quite a disheartening experience - there’s just so much LLM generated crap. The dead internet theory doesn’t feel as fringe as it once did.
gandreani 5 days ago|||
Oops I mixed up my tabs. My bad