Group variables

By default, Ansible will look for group variables in the same directory as the playbook called group_vars for variables that can be applied to the group. By default, it will look for the filename that matches the group name in the inventory file. For example, if we have a group called [nexus-devices] in the inventory file, we can have a file under group_vars named nexus-devices to house all the variables that can be applied to the group.

We can also use a special file named all to include variables applied to all the groups.

We will utilize this feature for our username and password variables. First, we will create the group_vars directory:

$ mkdir group_vars

Then, we can create a YAML file called all to include the username ...

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.