Looping through Dictionaries in Ansible

Note that this post uses NTC-Ansible. Installation instructions can be found here.

In the Understanding Ansible Output Structure post we saw how to extract a single entry out of a dictionary. We saw that it’s possible to do it using the map() filter too. However, what if we want to extract all entries in the dictionary, how would we go about that? The answer is simple – use with_dict . For example, this Playbook:

Produces the following output:


This playbook is available here in my Github repo.

Knowledge Base

See the Ansible section of my Knowledge Base for more information.

As always, if you have any questions or have a topic that you would like me to discuss, please feel free to post a comment at the bottom of this blog entry, e-mail at will@oznetnerd.com, or drop me a message on Twitter (@OzNetNerd).

Note: This website is my personal blog. The opinions expressed in this blog are my own and not those of my employer.