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
On Tuesday, March 31, 2015 at 4:16:58 PM UTC-4, Nico K. wrote:
>
> Hey Brian,
>
> Thanks for that, works like a charm.
>
> I did notice there are a bunch of quoting issues going on, for instance:
>
> x:
> - y: b
> z: c
> - y: "{{ d }}"
> z: "{{ e }}"
>
> Works fine, where-as defining the structure as per my initial post the
> variable evaluation fails ( end up with {# x.item #} or group_id's that do
> not evaluate.
> Now I will say, the variables are defined in group_vars over a couple of
> different groups and are then passed in through a 'with_items' iterator in
> the actual role.
>
> Anyway, it's not a real problem since defining it as above works as
> expected.
>
> Thanks again for your suggestion!
> Nico
>
>
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f9383dd3-1b7a-4590-8f25-eaadf53a2325%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.