How to loop over this dictionary in Ansible?

Question:

Say I have this dictionary

and for now I just want to loop over each item (key), and then over each item in the key (value). I did this

And I get this. It is of course correct, but is NOT what I want.

I want to get an output that says

IOW, how can I write a task to iterates over the dictionary so it goes through each key, and then the items within each key? In essence, I have a nested array and want to iterate over it?

Answer:

Well, I couldn’t find a very easy way to do it, however, with a little bit of jinja2, we can achieve something of this sort:

And, when the playbook is run:

Leave a Reply