I read key1=value1 key2=value2
style dictionaries all the time in ansible playbooks that are supposed to be written in YAML. On the other hand I didn't find any documentation for this format and there seem to be cases where it doesn't work for me. What is the exact specification and where can I find it?
In Ansible key=value
is not used for dicts in general.
It is an alternative syntax to pass parameters to actions/modules, like:
- name: restart apache
service: name=apache state=restarted
Here you pass name
and state
parameters to service
module.
From YAML perspective name=apache state=restarted
is a string. There's some magic done under the hood by Ansible to split it. But it become unreliable and cumbersome with complex arguments, so I always use native YAML syntax:
- name: restart apache
service:
name: apache
state: restarted
And this key=value
works only for modules/actions parameters, you can't define dictionaries like this:
vars:
# this will give you a string, not dict
mydict: key1=value1 key2=value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With