In this lab, you will create a ~/proj/ directory containing an ansible.cfg file, a static inventory file, and a group_vars/ directory.
In the group_vars/ directory, create group files that set values for variables that make it possible to connect and authenticate automatically to devices.
Outcomes
You should be able to create a simple Ansible project directory that contains a static hosts inventory, an Ansible configuration file, and a group_vars/ directory with files that sets variables needed to automate the connection and authentication process.
Open a terminal window on the workstation VM.
Table 1.4. Lab Network Managed Resources
| Host | OS/NOS | Credentials |
|---|---|---|
| spine01 | VyOS | user: vyos, password: vyos |
| spine02 | VyOS | user: vyos, password: vyos |
| leaf01 | VyOS | user: vyos, password: vyos |
| leaf02 | VyOS | user: vyos, password: vyos |
| cs01 | IOS | user: admin, password: student |
Procedure 1.1. Instructions
Create and change into the ~/proj/ project directory.
Create an Ansible hosts inventory file suitable for managing devices shown in the Lab Network Managed Resources table.
Verify the inventory.
[student@workstation proj]$ansible-inventory -i inventory --graph@all: |--@network: | |--@ios: | | |--@cloud-services: | | | |--cs01 | |--@vyos: | | |--@leafs: | | | |--leaf01 | | | |--leaf02 | | |--@spines: | | | |--spine01 | | | |--spine02 |--@servers: | |--server01 | |--server02 | |--server03 |--@ungrouped:
Create a local ansible.cfg file that contains your customizations.
Use your favorite text editor to create an ansible.cfg file with contents similar to the following:
[defaults] host_key_checking = False inventory = inventory ask_pass = True gathering = explicit [persistent_connection] # avoid timing out when configuring slow 102 VM command_timeout = 180 connect_timeout = 100 connect_rety_timeout = 100
Create a ~/proj/group_vars directory to contain further customizations.
Populate the group_vars/ directory with group files that set the connection method and authentication details (ansible_user).
Use your favorite text editor to create group_vars files for the network, vyos, and ios host groups.
Create them with the following contents:
[student@workstation proj]$cat group_vars/networkansible_connection: network_cli[student@workstation proj]$cat group_vars/vyosansible_network_os: vyos ansible_user: vyos[student@workstation proj]$cat group_vars/iosansible_network_os: ios ansible_user: admin
Check your work.
[student@workstation proj]$ansible -m debug -a "var=ansible_user" vyosSSH password:vyosleaf01 | SUCCESS -> { "ansible_user": "vyos" } leaf02 | SUCCESS -> { "ansible_user": "vyos" } spine01 | SUCCESS -> { "ansible_user": "vyos" } spine02 | SUCCESS -> { "ansible_user": "vyos" }[student@workstation proj]$ansible -m ping vyosSSH password:vyosleaf01 | SUCCESS -> { "changed": "false" "ping": "pong" } leaf02 | SUCCESS -> { "changed": "false" "ping": "pong" } spine01 | SUCCESS -> { "changed": "false" "ping": "pong" } spine02 | SUCCESS -> { "changed": "false" "ping": "pong" }
A hosts inventory, configuration file, and group variables supporting this particular inventory form a collection that provides an operational foundation for future automation projects. This would be a good time to commit and push it to a Git repository.
This concludes the lab.