Cumulative group variables?

I’m working on modeling our datacenter top-of-rack switches in Ansible, and have run into a potential problem with my approach. The basic idea is to use a hierarchal group structure that starts with general purpose (tor), and then get more specific for each deployment based on application that rack is supporting:

`
[tors]

[app1switches]
app1switch1
app1switch2

[app2switches]
app2switch1
app2switch2

[tors:children]
app1switches
app2switches

`

I want to abstract all my VLAN configuration into group-defined variables. In this example, let’s say that there is at least one VLAN that is standard across all TORs, and then each application has their own unique set of VLANs that also need to be applied. My idea was to create group variable files such as:

`

So, the problem is that you can’t combine lists, but you can merge dicts (it’s a config setting, default=false).

This will require either a double for loop or, (my preference, especially if you are going to use this type of construct a lot) a filter to combine them.

`

file: /group_vars/tors

example filter: https://github.com/chepazzo/ansible-misc/blob/master/filter_plugins/listoflists.py#L35

Now, your template looks like this:

{% for vlan in vlans|collapse_dict %} set vlan {{ vlan.name }} vlan-id {{ vlan.id }} {% endfor %}