Looping over dictionaries

Looping over a simple list is nice. However, we often have an entity with more than one attribute associated with it. If you think about the vlan example in the last section, each vlan would have several unique attributes to it, such as the vlan description, the gateway IP address, and possibly others. Oftentimes, we can use a dictionary to represent the entity to incorporate multiple attributes to it.

Let's expand on the vlan example in the last section for a dictionary example in chapter5_6.yml. We defined the dictionary values for three vlans, each with a nested dictionary for the description and the IP address:

    <skip>     vars:       cli:         host: "{{ ansible_host }}"         username: "{{ username }}" password: "{{ password }}" ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.