I am trying to process a nested data structure and can’t find a suitable syntax to let me do it. Ansible only seems to allow one level of looping, or two with sub-elements.
for each VPC
for each tier
for each subnet
create subnet
I.e., three nested levels?
I don’t have to do it this way; I can flatten the data structures, but the data structure is naturally nested, so it would be nice to be able to use it in that form.
I guess vpcs is also a list, you just forgot the dash?
If so you can go "old" school and user include_tasks with with_items that support many nested levels.
I couldn’t bear to use separate YAML files, so instead I wrote set_fact: loops to create a flat list out of the nested structure. The end result looks something like this:
This lets me loop over the same list multiple times, taking what I need at each pass, and element has all the info I needs. It’s not as nice as being able to loop over the real nested structure, but it’s close. The main thing is that I can record the info correctly in the nested structure, and generate the list automatically; I don’t have to create all that repetitive data by hand.
BTW the above is indicative, not the real thing. There’s more detail in there in real life