Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

66% Positive

Analyzed from 2391 words in the discussion.

Trending Topics

#pyinfra#ansible#python#code#more#https#yaml#infrastructure#inside#used

Discussion (55 Comments)Read Original on HackerNews

ssddanbrownabout 3 hours ago
I've been using PyInfra for a while, albeit just for simple automation (Updating systems, checking certain stats) and I'm a big fan. Compared to Ansible, I found the docs, syntax and usage patterns much easier to get on with. Might just be a preference thing, but I always had trouble going through the Ansible docs.

Ran into some bugs, like one machine that seems to cause errors and mess up the output on restart, although that looks like it might have been addressed in this release.

If it helps, I put together a video when initially exploring PyInfra: https://www.youtube.com/watch?v=S-_0RiFnKEs

wowi42about 2 hours ago
Glad it clicked. The Ansible vs PyInfra docs gap isn't really preference, YAML plus Jinja plus a custom DSL is just more cognitive load than plain Python with type hints. Once you can grep the source and read it like normal code, going back feels rough. On the restart bug: if it resurfaces, an issue on GitHub with the OS, connector (ssh/local/docker), and raw output would help a lot. The 3.x line cleaned up a bunch around connection handling and output buffering, so there's a decent chance it's already fixed. Thanks for the video, will watch. Hands-on intro content is exactly what the project needs more of.
wowi42about 4 hours ago
Disclosure: PyInfra core contributor here.

We just shipped 3.8.0.

PyInfra is an agentless infrastructure automation tool. Same job description as Ansible, Salt, Chef. SSH into hosts, describe desired state, it diffs and converges. No agent, no central server, no daemon.

The difference: your "playbook" is just Python. Not Python cosplaying as YAML. Not Jinja smuggled inside YAML inside a Helm chart inside a Kustomize overlay. Actual Python:

    from pyinfra.operations import apt, files, server

    apt.packages(packages=["nginx"], update=True)
    files.template(src="nginx.conf.j2", dest="/etc/nginx/nginx.conf")
    server.service(service="nginx", running=True, enabled=True)
Idempotent operations. Facts gathered from hosts, branched on with normal `if` statements. Real loops, real imports, a real debugger, real type hints. Your editor autocompletes arguments because, brace yourself, they are just function signatures.

About YAML. Wonderful format. For about eleven minutes. Then someone needs an `if`, and you have `{% if %}` inside a string inside a list inside a map. Then someone types `no` as a country code for Norway and it ships to prod as `False`. Then someone indents with a tab and the parser dies without saying where. Congratulations, you reinvented a programming language. Badly. The honest move is to admit you wanted code, then write code.

PyInfra skips the eleven good minutes and goes straight to code.

Release notes in the link. Happy to answer questions.

Infrastructure as Code, not infrastructure as YAML.

mxey5 minutes ago
The problem is that it is actually not just Python, branched with “normal if statements”: https://docs.pyinfra.com/en/3.x/deploy-process.html#checking...
vardalab7 minutes ago
Yeah, but I have Claude Code or Codex do this Ansible stuff and they do just fine with all this and then there's a gazillion of examples that they can lean on and once the patterns are established, it's pretty smooth. Opus 4.5 was when the big inflection was I was heavy into automation all summer. It was Opus 4.0. It was like pulling teeth. And then when 4.5 came out, it was just beautiful.
zahlmanabout 1 hour ago
As a heads-up, your comments here were flagged. I think some people must have thought your (current) writing style rather LLM-ish.
mrkstu20 minutes ago
It obviously was LLM assisted, but I think collectively we will have to get over our distaste for text that has some LLM’isms in spots as long as it isn’t obviously completely outsourced to a bot, unless we just want to shut down message boards completely.
wowi42about 1 hour ago
Ah shit...
js213 minutes ago
I'm glad to see PyInfra is still under active development. I don't currently use PyInfra, but I previously used it for a couple years to manage a build farm of about 100 Mac Pros. Those machine had previously been partially managed by Chef to ill effect.

I found PyInfra to be a great tool for the job at hand. Even though it didn't have many of the operations I needed, I found it easy to write new operations specific to macOS management tasks.

I recently looked at it again to help build EC2 Mac AMIs in combination with Packer, but I ended up with pydoit this time instead.

coreylaneabout 3 hours ago
I used ansible for years and pyinfra is very approachable since it has similar concepts, like inventories, common operations like files.put, server.shell, loving it so far, and it is quite fast
mkobit26 minutes ago
I have started to adapt https://testinfra.readthedocs.io/en/latest/, which looks similar in style to this from the verification side. Having previously used Salt, Ansible, and Chef at other companies, this looks great from a UX perspective compared to those other tools.
V__about 3 hours ago
Has anyone used this and ansible and is able to give a short comparison with likes and dislikes?
Boxxedabout 3 hours ago
Pyinfra is what ansible should have been. It's straight python rather than a janky mix of yaml, templates, and bolted-on control flow primitives.
polski-gabout 2 hours ago
There is this: https://github.com/seantis/suitable

But the main guy who developed it at that company left, so no idea on its longevity.

Boxxed8 minutes ago
Yeah I guess; I'm generally not a fan of solving a problem by adding another layer of shit on top.
matthiaswhabout 3 hours ago
I switched from Ansible to Pyinfra for my homelab, and continue to use Ansible at work.

The biggest difference is that Pyinfra is simply Python code. It's incredibly easy to control the system in whatever manner you need to. You can probably do the same thing in Ansible, but it's never quite as obvious how to do it. This also means it's much more clear where and why things work the way they do in Pyinfra, where in Ansible I end up digging through numerous role files to try to find where some variable gets injected.

SteveNutsabout 2 hours ago
The worst part of Ansible is data manipulation, what would be an easy dictionary operation in Python is a huge mix of lookups in Ansible.

Incredibly frustrating that the data you want is right there but you can't easily grab it.

gchamonliveabout 2 hours ago
If Jinja templating for data manipulation gets too complex or inconvenient, you can create your own module in ansible and use python code for data manipulation. But at this point you are better served with plain python which I think is where pyinfra should shine. I want to take a look though at how hard it is to implement your own module for it.
hylarideabout 3 hours ago
At a previous job we used it to test our ansible playbooks via molecule, which were part of a CI/CD pipeline to create AWS AMIs.

It worked well and was nicer to deal with than test kitchen for testing UNIXy things (is service running and/or enabled, does file have right permissions, does file include $TEXT, etc). It was very useful for us during big linux upgrades, such as when ubuntu went from upstart to systemd. It can also be good at capturing edge cases with brittle outcomes (especially as ansible went through enormous changes after the red hat acquisition).

Dislikes? I had to fight with pyenvs a bit..

gegtikabout 3 hours ago
was this before uv? i feel like my pyenv struggles basically ceased once I started using it
hylarideabout 3 hours ago
I used it between 20016-2023 and since we were not a python shop, I never used any other package managers. It was never an issue with CI/CD pipeline, but iterating locally was always a fight to getting molecule to pick up the right pyenv. It got better towards the end, though.

Honestly the bigger issue was testing x86 docker images on an arm mac, as molecule didn't cleanly support cross platform images and we did pull in x86 binaries for our playbooks (by the end of my time at said company, I was also directly managed by product managers who didn't care about tech debt and I couldn't deal with the otherwise desirable idea to move our compute to ARM - a rant for another day). This may also be fixed now.

wg0about 2 hours ago
I used ansible for building simple logging appliance (something like Elasticsearch + Dashboards + other tooling) and I found it very difficult to reason with specifically python code snippets within YAML.

Switched to Pyinfra and the difference is day and night. You write python code you can organise your stuff into functions, classes and whatever you like and then instantiate them as you like. Highly reusable configuration.

You have full pwoer such as you can call boto to fetch the list of servers to target, filter base on tags and what not. Only sky is the limit because it is NOT a DSL (or YAML) rather full blow real python.

haolezabout 1 hour ago
Ansible includes modules to handle cloud resources as well, such as AWS Lambda.
bityard28 minutes ago
Is there anything like Ansible Tower or Semaphore for PyInfra? Or some more generic tool that would work similarly?

I could likely vibecode something up if I had to, but I'm interested in a job orchestration system that can run things like upgrades, scheduled backups, ideally with a nice dashboard showing successful/failed jobs.

eb0laabout 2 hours ago
This reminds me of Nortel Command Console back in 2000-2005!

I worked for a telco company that had a lot of Nortel Passport devices (does anyone know what Frame Relay is?). We started changing the network from Nortel to Cisco. Cisco used telnet (later SSH), but Nortel people were extremelly reluctant to switch.

Turns out the Nortel network managment system (nortel nms) had a very interesting feature: you could open the command console to connect to one of the passport devices... or you could connect to a device group (or all the network) and run the same command in all devices.

This was great for auditing which version had every single device in the network... or for changing access-lists globally.

cpachabout 2 hours ago
We had lectures on Frame Relay and stuff like that in uni, but I’ve never ever touched that stuff (:
hathymabout 3 hours ago
i tried ansible before and hated it, this idea is genius.
bestonyabout 2 hours ago
This looks great! pyinfra will integrate better with my other code, and installing it with uv fits my workflow better. Thanks for the post. I'll give it a try. I think some of my Caprover initialization tasks could also be handled by pyinfra.
appplicationabout 3 hours ago
The is cool, thank you for sharing. I was just thinking about onboarding to ansible since I’ve just been following a manual checklist of commands for my remote server but based on positive feedback here I’ll probs oh give this a shot. Only downside is I imagine LLMs are probably a little more proficient at ansible just due to volume of training data.
coreylaneabout 2 hours ago
I never depend on a models built-in training when using third-party libraries. Providing tons of additional context to the model like a skill, example repos, or context7 snippets that I manually curate is more effort up-front and takes longer, but the results are worth it.

Stuff I threw into the inputs before working with pyinfra

https://github.com/pyinfra-dev/pyinfra-examples

https://context7.com/websites/pyinfra

Advertisement
sgarlandabout 1 hour 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.

odie5533about 3 hours ago
Does it have an equivalent to konstruktoid's hardening Ansible playbook?
wowi42about 3 hours ago
we could put it on our roadmap of examples :-)
hacker161about 1 hour 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.
benatkin23 minutes ago
The amount of repetition of @override seems unpythonic to me, but maybe that's python being unpythonic.

https://github.com/pyinfra-dev/pyinfra/blob/3.x/src/pyinfra/...

mark_l_watsonabout 3 hours 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-epochabout 3 hours 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.
ktm5jabout 3 hours ago
This seems cool, I'd particularly be interested if their 10x faster than Ansible claims pan out. Has anyone here used PyInfra? If so what's your experience been like?
eurekinabout 3 hours ago
On my homelab. It really feels like a dream come true for my usecase. No more puppet agents. No more declarative syntax, that you have to work around to do basic imperative ways. Or use a module, that stopped being maintained 3 years ago. Just plop a file here and there through ssh.
alanwreathabout 3 hours ago
Same here, my home lab is all pyinfra. I’m not sure if it’s my previous experience with ansible that made it simple for me or just the relative size of my home lab compared to larger companies where I’ve used ansible - but it seemed much easier to me and easier to follow.
e12eabout 2 hours ago
I wonder if this is 10x faster than Ansible with ssh multiplexing or not?

https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing

pbronezabout 1 hour ago
How does this compare to Salt Stack?

“Built on Python, Salt is an event-driven automation tool and framework to deploy, configure, and manage complex IT systems. Use Salt to automate common infrastructure administration tasks and ensure that all the components of your infrastructure are operating in a consistent desired state.”

https://docs.saltproject.io/en/latest/topics/about_salt_proj...

bijowo1676about 1 hour ago
salt is heavy: it has client, server, agent. it equires installation, consumes resources, etc.

pyinfra is just python that gets transpiled into ssh commands

subhobrotoabout 3 hours ago
Congrats on shipping 3.8.0!

If you're a software engineer who wants to setup and maintain infrastructure, give PyInfra and Pulumi a go!

Huge fan of PyInfra. For my homelab, I use Pulumi with Python and PyInfra to build fully declarative intent based infrastructure. You can use actual software engineering principles like composition, inheritance, DI to setup and wire your infrastructure and services. One of the benefits of this is your infrastructure and services are now self documenting (have them write out a mermaid diagram!) and easily testable using pytest (from cheap unit tests to extensive integration tests (I use Incus)).

Instead of Pulumi, I originally used Terraform CDK with Python before CDK got IBM'd. The migration to Pulumi was refreshingly painless. My original reason for not choosing Pulumi was the crippled state of the open source, self hosted backend support a decade ago but it looks like that is now way more mature and less crippled.

PyInfra is a breath of fresh air compared to Ansible - its not just fast, it's more Pythonic, so IDE features actually work, readable, maintainable, debuggable. I call it infrastructure for software engineers.

If anyone wants to use an AI agent to try out PyInfra - One issue I've faced is that PyInfra was rearchitected in v2 (and some more in v3?) but what belongs in v1 vs v2 vs v3 isn't very clear, so an AI agent could spend a lot of time writing v1 code, having it fail and iterate to v2 and then to v3.

The official site uses the version in the URL as the namespace but it seems like the SOTA AI agents don't pay much attention to that.

Maybe writing a llms.txt for PyInfra v2, or v3 would be an extremely useful task to help with onboarding newcomers?

---

The original post by the OP https://news.ycombinator.com/user?id=wowi42:

Disclosure: PyInfra core contributor here. We just shipped 3.8.0.

PyInfra is an agentless infrastructure automation tool. Same job description as Ansible, Salt, Chef. SSH into hosts, describe desired state, it diffs and converges. No agent, no central server, no daemon.

The difference: your "playbook" is just Python. Not Python cosplaying as YAML. Not Jinja smuggled inside YAML inside a Helm chart inside a Kustomize overlay. Actual Python:

    from pyinfra.operations import apt, files, server

    apt.packages(packages=["nginx"], update=True)
    files.template(src="nginx.conf.j2", dest="/etc/nginx/nginx.conf")
    server.service(service="nginx", running=True, enabled=True)
Idempotent operations. Facts gathered from hosts, branched on with normal `if` statements. Real loops, real imports, a real debugger, real type hints. Your editor autocompletes arguments because, brace yourself, they are just function signatures. About YAML. Wonderful format. For about eleven minutes. Then someone needs an `if`, and you have `{% if %}` inside a string inside a list inside a map. Then someone types `no` as a country code for Norway and it ships to prod as `False`. Then someone indents with a tab and the parser dies without saying where. Congratulations, you reinvented a programming language. Badly. The honest move is to admit you wanted code, then write code.

PyInfra skips the eleven good minutes and goes straight to code.

Release notes in the link. Happy to answer questions.

Infrastructure as Code, not infrastructure as YAML.

DandyDevabout 1 hour ago
There is a PR open for llms.txt and llms-full.txt. We'll try to merge it soon!

Disclosure: another contributor here.

subhobrotoabout 1 hour ago
It's amazing to see more contributors!

TBH, I was worried a few years ago that there was basically just one (original) contributor. This now gives me added trust that I'm taking the right decision to lean heavily into it.

I hope more people start using pyInfra.

Thank You for your contribution and attention!

weakfish31 minutes ago
+100 to pulumi, I love it with TypeScript
gandreaniabout 3 hours 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

alanwreathabout 3 hours ago
This is spam - btw this is the first spam I have ever come across on hacker news
gandreani1 minute ago
Oops I mixed up my tabs. My bad
akshaykarthikabout 3 hours ago
I think this was likely an attempted response to https://news.ycombinator.com/item?id=48008326
alanwreathabout 3 hours ago
Yes - that’s got to be it.
electrolyabout 3 hours ago
FWIW, if you turn on "showdead", there is a ton of spam on HN. The mods are just really good.
JSR_FDEDabout 1 hour 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.