Host variables

We can further separate out the host variables in the same format as the group variables. This was how we were able to apply the variables in the Ansible 2.5 playbook examples in Chapter 4, The Python Automation Framework – Ansible Basics, and earlier in this chapter:

$ mkdir host_vars

In our case, we execute the commands on the localhost, and so the file under host_vars should be named accordingly, such as host_vars/localhost. In our host_vars/localhost file, we can also keep the variables declared in group_vars:

$ cat host_vars/localhost---"nexus_devices":  "nx-osv-1":    "hostname": "nx-osv-1"    "username": "{{ username }}"    "password": "{{ password }}"    "vlans": [100, 200, 300]    "l3_vlan_interfaces": True    "vlan_interfaces": [

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.