Ansible Connection Variables
The power of Ansible is in the way it automates hosts. This automation takes a lot of burden off the network administrator. Instead of making remote connections to a network device one at a time, Ansible allows you to create “playbooks” that gather information or configure the network device. For these “playbooks” to be run against the hosts you configured in the hosts file, you need to create variables. These variables are set in the group_vars and host_vars folder. Remember these folder names are important. All folders are specific to Ansible. Now let’s begin creating our folders!
Instructions
These instructions will show you how to create connection variables for a group of hosts and individual hosts!
First lets create the group_vars folder. In my VSCODE I am using the ~/Test_ansible repository for all my demonstrations.
Now create a file within the group_vars folder and name it “all.yml” .
***NOTE*** Remember all these folder and file names are specific to ansible. When connecting to a host Ansible will look for these file names.
Add This line of code to your “all.yml” file.
This code snippet above details what all these native Ansible variables do. Next we will create a file in the “group_vars” folder to specifiy a certain group of Nexus switches in the hosts file.
This “all.yml” file is used when there is not another file designating specific parameters for a single host device or for a specific group of hosts devices. These hosts device are all inputted and referenced in your Ansible repo’s hosts file. In this example I will set the type of OS for all my nexus devices, while keeping the rest of the login parameters the same, as referenced in the “all.yml” file.
Input this code to make sure all devices in [nxos] group will use have the correct connection variable for Ansible to manage.
Note that the only things we added here were the USER and the OS type variables. Every other connection variable will be referenced by the “all.yml” file.
This concludes the basics of setting group and host variables in Ansible . Remember to check the Ansible Project's homepage for more information on setting your variables.
Related articles
Related Links | |
This is the homepage for Ansible project. | |
Last updated