5 ms·
My biggest problem with Ansible is the YAML, doing anything with loops is horrendous & trying to mangle nested variable types requires a StackOverflow post ever
by polski-g 2y ago
My 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...
- movedx 2y agoBut you can just write a small module in Python, have it do the looping logic for you, install it at the root of your project's configuration-as-code repository, and then use the module in the YAML, removing the need to do complex, ugly loops in YAML. Is there a reason this isn't an option for you?