5 ms·
I current use Ansible to setup both local and remote hosts. I've been very happy with it, and love that Pyinfra intends to support the Ansible connector. My ma
by activatedgeek 2y ago
I current use Ansible to setup both local and remote hosts. I've been very happy with it, and love that Pyinfra intends to support the Ansible connector.
My main gripe with Ansible is the YAML specification. Ansible chooses to separate the task specification and task execution.
Pyinfra chooses to directly expose the Python layer, instead of using slightly ugly magic functions/variables. I like this approach more since it allows standard Pythonic control flow instead of using a new (arguably ugly and more hassle to maintain) grammar.
Excited for Pyinfra!
- WesolyKubeczek 2y agoI'm only using Ansible because of its extensive documentation and mindshare, but my best successes with it were when I let go of the idea that the playbooks specify state "declaratively". I now treat them as imperative steps where each step is being checked as to whether it needs to be done or not, and it has vastly simplified my mental model of what Ansible is actually doing.
- letmeinhere 2y agoI think of ansible as a declarative-imperative lasagna, where each playbook is a desired state, achieved by an imperative sequence of plays, which themselves are desired states, achieved by a sequence of roles, which have the same properties, and then tasks too below that, finally resolving to plain old imperative Python. It's all pretty messy but useful.
- WesolyKubeczek 2y agoI never grokked this “plays” and “roles” business. All in all, this clever and cute terminology gives me creeps. I only use “playbooks” as series of tasks, more or less. Maybe I need an explanation “like I’m just a programmer/sysadmin and I need to use boring terms years old” of what is what, every explanation so far (when I bothered to look for it last) was too invested in this theatrical terminology, so I gave up and stuck to what worked after a command or two. Same with Chef and its galore of cooking words, but thankfully I don’t have to use Chef.
- rmetzler 2y agoAn Ansible playbook is usually the main entrypoint, it consists of a list of plays. Each play has hosts and a list of tasks to run at them. Because people wanted to reuse their code, the abstraction of roles was created. A role is something like „setup basic OS stuff“, „create this list of users“, „setup a Webserver“, „setup a database“. The association, which roles to run on which machine still happens in the playbook.
- WesolyKubeczek 2y agoI'm using include_tasks: and import_playbook:, like an animal :)
- trallnag 2y agoYou can't share a set of tasks on Ansible Galaxy without wrapping it in a role
- zanecodes 2y agoTo this day I'm miffed that Chef has "cookbooks" which contain "recipes," which contain... "resources." Why not "ingredients??" It was right there!
- ornornor 2y agoAnsible is useful but so confusin (to me anyway). The way I see roles vs playbooks is whether I’m going to reuse it or not. Roles are more generic playbooks in a sense that I can share with others or across deployments (for example setup a reverse proxy, or install a piece of software with sane, overridable defaults. I can then use roles within playbooks to tweak the piece of software’s configuration. If it’s a one-off confit/setup then I’ll use a playbook. I don’t know if it’s the right paradigm (I don’t think it’s explained well and clearly in the docs), but using this rule of thumb has helped me deal with it. Of course, any role can be a playbook and vice versa since they do the same thing functionally, it’s all about reusability and sharing. Kinda how you have libraries in software: role = library, playbook = the software you actually want to write.
- 2y ago
- polski-g 2y agoMy biggest problem with Ansible is the YAML, doing anything with loops is horrendous & trying to mangle nested variable types requires a StackOverflow post every time. A few years ago, I found a library that lets you utilize Ansible's tasks in raw Python, without the huge hassle of using the Ansible Python API. I cannot find it again however. But PyInfra looks great.
- Fizzadar 2y agoThis alone is the entire reason I started working on pyinfra, loops in YAML is just evil.
- bruh2 2y agoWhy did you choose to roll your own modules rather than do what's described in the comment you replied to, i.e. provide a Python layer for interacting with the rich set of available Ansible modules? Not trying to be rude ofc, I'm sure you considered it and have a good reason – just curious as of what it is. An incredible project you put there, nonetheless:)
- Fizzadar 2y agoNot rude at all :) When I first started (not sure if this is still the case?) Ansible would push Python code to the target machine and execute there, meaning it wasn’t actually agentless. I always thought of pyinfra as copying what a human would do if configuring a server by hand over SSH, so new modules that use only shell commands were needed.
- geerlingguy 2y agoIt could be interesting if you could write a translator to use any Ansible module with this, and vice versa.
- natebc 2y agoI recall the Ansible Python API to be labeled as Interal Use Only and subject to change on a whim because of that. That at least discouraged using ansible in that way. Seems they still kinda discourage it but do have examples at least. https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html https://docs.ansible.com/ansible/latest/dev_guide/developing...
- nijave 2y agoReal Python instead of templating (Jinja in YAML) would be nice. In Ansible, it's fairly arduous to try to reshape data from command outputs into structures that can be used in loops in other tasks--especially if you want to merge output from multiple commands. Main usecase is more dynamic playbooks where you combine state from multiple systems to create a new piece of infrastructure. I think templating yaml or templates inside yaml is a bit of an anti pattern.