by pmoriarty · 6y ago · 0 comments
What a shitty idea that turned out to be.
And it's not simple. It's just as complicated as its competitors. It's full of weird quirks and corner cases, and just like all the other tools in its class it feels like it was more congealed and cobbled together out of random bits than designed in a consistent, elegant way.
Systems administration and automation is complex.
That being said I've found Ansible to be the most useful tool for the job. It does the things I need it to and new modules are usually easy to incorporate into my work if I need specific tasks done. It has its shortcomings but it hasn't blown up into an unmaintainable mess like many of the other solutions I've poured hundreds of hours into.
YAML is not fun, but it's been good enough for the task of pushing parameters around.
Recently I had a use-case where I wanted to re-use some data from a defined variable (list of objects) in a second module, but the format had to be different. In python I would have done something like new_var=[{a:i['a'], b:i['b']} for i in old_var], but apparently that is impossible in ansible. The best solution I was able to find after lots of searching was to to pass new_var to a jinja2 template which would render new_var as text, then run that through a json interpreter and set that as new_var. Absolutely rediculous.
It astounds me that a tool BUILT on python lacks any semblance of python's biggest feature, list comprehension.
But "writing" Ansible playbooks is definitely not python. It's its own dsl bastardized between yaml, jinja2 and reserved/special keywords. This is the worst thing I can say about the whole toolkit.
Unfortunately, I'm really productive with it and when I return to work I've written 3+ years ago:
A) It still runs
2) I can read and understand the intent of my playbooks
The hardest thing for some people seems to be whitespace issues, but that can be resolved easily enough by integrating a linter into your environment, or minimally showing whitespace characters in your editor.
Even allowing a playbook to opt out of the default delimiters in the same way one can in a template file[1] would allow a transition out of that mess
#jinja2:variable_start_string:'<%', variable_end_string:'%>'
- debug:
msg: <% my_var %> needs no quoting!
1 = https://docs.ansible.com/ansible/2.10/collections/ansible/bu...But really, that's not the problem. The problem is when you inherit someone else's playbook that is itself trying to do a hackjob around a community playbook.
(If you dig into the details, you will find some "atrocious hacks" as the sibling comment puts it, but because of how it works, the hacks are almost completely encapsulated at build time and those builds are reproducible, so there's much less to worry about when you're deploying/provisioning.)