by emacsen · 2y ago · 0 comments
It is a configuration management tool, like Ansible?
Is it meant for running one-off commands across the infrastructure, like Salt?
It says it integrates with Terraform, so it's not a provisioning tool...
What does it do different (and presumably better) than other tools?
The Getting Started guide doesn't cover this. The FAQ doesn't cover this, and the Docs doesn't have an Introductory section to cover this.
It's disheartening to find a potentially interesting project, but not really know what it does and how it might fit in your workflow.
It can also run one-off commands across the infrastructure (like Tentakel: https://pypi.org/project/tentakel/ ).
I've been using Pyinfra for some time. It's good enough for me.
A couple years ago I inherited about 100 Mac Pros that are part of $dayjob's CI infrastructure. They had been managed over the years using a combination of shell scripts, Chef, and manually via VNC. No two machines were alike. The Chef recipes had all bit-rotted and weren't usable and due to $reasons were based on an old version of Chef that $company was stuck on.
So I looked around for alternatives, and being most comfortable in Python, I explored Ansible, Salt, and Pyinfra.
Ansible seemed like the obvious choice, but it has very few playbooks/actions for macOS systems. I was going to have to write my own. As I dug into its documentation, I found it was taking me a long time to wrap my head around all that I needed to do and started to sour on its complexity. This is a matter of taste, but I just didn't find Ansible very welcoming. I wanted something simpler.
I had previously used Fabric, so considered using it again. But Fabric offers too little (it's really not much more than parallel ssh-if you want idempotent operations you have to write that yourself), and I don't agree with the direction it took with version 2.x.
Then I found Pyinfra. It took me less than 30 minutes to understand it in its entirety. It's conceptually simple: you have an inventory of machines that it connects to in parallel over ssh. You provide it with a deploy script that combines facts and operations. Pyinfra uses the deploy script to gather facts about each machine, then you use those facts to decide whether you need to perform any operations. It then performs those operations on each machine as needed. The inventory file, deploy script, facts, and operations are trivial to write for someone comfortable with Python. It's all Python with the facts and operations being decorated functions. There is no DSL to learn. (It comes with a bunch of pre-written facts and operations, but they are mostly for Linux systems. I had to mostly wrote my own for macOS, but I found them really easy to write.)
I had it operational the same day I found it. I used it to successfully get all of the Mac Pros into consistent state: things like system settings, installing Xcode, automating installs of brew packages all at the same version, installing JVMs, updating and upgrading macOS, installing Sentinel One, etc.
I've been very happy with it, even contributing a few PRs to fix small bugs and contribute minor functionality.
Yes
> Is it meant for running one-off commands across the infrastructure, like Salt?
Also yes.
> It says it integrates with Terraform, so it's not a provisioning tool...
The TF integration is specifically to use TF as an inventory source - ie TF to create resources and pyinfra to then configure them.
> What does it do different (and presumably better) than other tools?
The homepage covers the highlights, I originally created pyinfra because debugging Ansible was complicated (no plain stderr as not "just" commands on the remote side) and slow, but things have evolved significantly since then.
> The Getting Started guide doesn't cover this. The FAQ doesn't cover this, and the Docs doesn't have an Introductory section to cover this.
Hugely appreciate this feedback, this is super helpful and something I will attempt to make clearer.
---
Quick attempt at a better explanation: You write Python code that defines operations (either state "this apt package should be installed" or stateless "run this command"), provide an inventory of targets (SSH, local machine) and pyinfra executes it.
Roughly sits where Ansible does for configuring servers, but also solves the case of "how do I run this command across my server fleet" (which I believe Ansible can also do).
I genuinely think that an introduction with a few user stories would go a long way!
Well, Ansible is still dog-slow, so that part has not evolved...
I found that pretty clear to be honest.
That's what I discovered by reading the homepage.
Reasonable people can 100% disagree about whether yaml is the correct packaging for those operations, and ansible is a bit too imperative for my liking, but as far as "I have one hammer..." it does all the things
But practically, these tools have their areas of speciality.
I feel as though we're splitting hairs here, given there is, to the best of my knowledge, no `resource remote_file make_sshd_config { inventory_host = "whatever" dest = "/etc/sshd_config" src = "./sshd_config.tmpl" vars = {...} }` in TF. There is template, and there is local_exec and the rest is a Simple Matter Of Programming :-/
I'm waiting patiently for someone to chime in "well, just spawn ansible in local_exec" as if they're missing the point
And that's cool- Ansible is a bit of an oddball system, but then I'm still left wondering, why is this better, or why it is better for the author at least?
I've used cfengine, Puppet, Chef, bcfg2 (briefly) and ansible. I want to know what makes this tool different and better. :)