What if you go a few levels deeper? Say I have different rules for "all", "location", "groupA", and "groupB". I will always have base rules for "all". I may or may not have base rules for "location", "groupA", or "groupB".
Right now I am handling it like this. I am using Ansible 1.8.2 with hash merging turned on. I have a hash in each group_var that needs it.
group_vars/all:
base_rule:
all:
rule:
- rule1
group_vars/location:
base_rule:
location:
rule:
- rule2
group_vars/groupB:
base_rule:
groupB:
rule:
- rule3
Then when I want to call them in a task I would do so like this:
- name: echo base rules
shell: /usr/bin/echo item.1
with_subelements:
- base_rule
- rule
In a jinja template I would use:
{% for key, value in base_rule.items() %}
{% for key, a in value.iteritems() %}
{% for rule in a %}
{{ rule }}
{% endfor %}
{% endfor %}
{% endfor %}
I was wondering if there were a better way do accomplish this. If I were to use union I would have to list out ever possible instance of the hash that I am trying to merge right? Something like:
{{ base_rule|union(location_rules)|union(groupA_rules)|union(groupB_rules) }}
Or is there a way to accomplish this without listing each hash that needs to be joined?
Thanks,
John