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 file name that matches the group name. 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 applied to the group.

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

We will utilize this feature for our username and password variables:

$ mkdir group_vars

Then, we can create a YAML file called all to include the username and password:

$ cat group_vars/all
---
username: cisco
password: cisco

We can then use variables for the playbook:

    vars:
nexus_devices: {
"nx-osv-1": {
"hostname": "nx-osv-1",
"username": "{{ username }}",
"password": "{{ password }}",
"vlans": [100, 200, 300],
<skip>
"nx-osv-2": {
"hostname": "nx-osv-2",
"username": "{{ username }}",
"password": "{{ password }}",
"vlans": [100, 200, 300],
<skip>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.219