According to this blog post: https://www.ansible.com/blog/loop-plays-past-present-future with_dict is going away. All my roles rely heavily on with_dict
and hash_behaviour = merge
merging to avoid configuring the same values over and over again. If I need to add or override a value, I just give it the same key in the correct vars file or on the command line.
As in:
roles/common/default.yml
champions: therock: "Yeah!" me: "Uh oh."
project/group_vars/web/main.yml
champions: me: "I win." them: "We lose."
project/host_vars/node1.yml (in web group)
champions: therock: "boom."
project/host_vars/node2.yml (in web group)
`
#champions just uses defaults.
`
So, node1 would look like:
champions: therock: "boom." me: "I win." them: "We lose."
node2:
champions: therock: "Yeah!" me: "I win." them: "We lose."
That lets me define common values in as few places as possible.
Is there a way to emulate using lookups?
Is there a better way to avoid defining common values in as few places as possible that I just haven’t seen yet?
What I’m trying to avoid is having a list of common, say iptable rules, configured in group_vars, but I have to modify or add just one of those rules a bit on a specific node. Using a list, or not merging hashes, would make me copy every single rule in the list from the group_vars file to the host_vars file. Otherwise I’d lose all but the one I modified or added.
Thanks.