I have a dictionary like this:
ppools:
one:
devices:
- abc
- cde
types: [ typea, typeb, typec]
branch: aaa
two:
devices:
- fgh
- ijk
types: [ typea, typeb, typec]
branch: bbb
I was wondering if I can somehow iterate over it so that the elements show up like so:
-
one, abc, typea
-
one, abc, typeb
-
one, abc, typec
-
one, cde, typea
-
one, cde, typeb
-
one, cde, typec
-
two, fgh, typea
-
two, fgh, typeb
…
Appreciate any advice.
It looks like I will need to flatten out the structure, just want somebody to confirm that there is no other obvious way.
You can iterate through it in a jinja template, though only for a fixed depth as you would need to code each iteration level manually (AFAIK)
{% for p in ppools %}
{% for devices in ppools[p].devices %}
etc
Restructing it slightly, you could use the “with_subelements” lookup:
http://docs.ansible.com/playbooks_loops.html#looping-over-subelements
Thank you, ended up flattening it and using subelements.