4 ms·
If you don't try throwing tons of logic in the YAML (and build a module or plugin where needed to keep that logic out of the YAML), then your playbooks are 99%
by geerlingguy 6y ago
If you don't try throwing tons of logic in the YAML (and build a module or plugin where needed to keep that logic out of the YAML), then your playbooks are 99% of the time simple YAML lists and dicts.
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.
- dnautics 6y ago> then your playbooks are 99% of the time simple YAML lists and dicts. 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.
- geerlingguy 6y agoWhen you inherit any code, it's always a mess, at least that's my experience. Sometimes a working mess, but it's rare to inherit nice code in any system. I could be biased since I've worked mostly with Python, Ruby, PHP, and Java.
- dnautics 6y agoof course, but debugging ansible YAML is exceptionally hard on account of the difficulty of decoding its quasi-declarative, quasi-imperative nature, the difficulty of knowing what the variables to be interpolated are (they could have been changed by other playbooks!), etc. You'll want at the very least a sane set of debug tools to figure things out when they go wrong. The other alternative is to just give up and rewrite the ansible script, which has been what I had to do on several occasions.
- mdaniel 6y agoWhitespace issues plague careless people in general, but ansible's choice to run jinja2 using its default delimiters of `{` was the million dollar mistake since it forces quoting to start a scalar with that character and it's quoting issues in yaml which compromise a significant portion of the SO questions I triage 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/builtin/template_module.html#notes https://docs.ansible.com/ansible/2.10/collections/ansible/bu...