The process of configuring network devices is illustrated with simple changes in this lab.
In this lab, you will automate simple operations on network devices.
Outcomes
You should be able to:
Consult local (ansible-doc) or web-based documentation to determine correct configuration statements to use with a given os_config module.
Configure devices using statements embedded in a playbook.
Configure devices by sourcing statements from a file.
Generate configuration files using Jinja2 and apply the changes to devices.
Open a terminal window on the workstation VM.
Create a playbook named rename-spine01.yml.
Use os_config statements in the playbook to change the local host name of spine01 on the network device to spineA1.
Do not forget to use the os_config module that matches the device.
Include a task that backs up the original configuration before the change is applied.
Perform the play in the rename-spine01.yml playbook.
Execute an ad hoc command to confirm that the host name of spine01 is now spineA1.
Also verify that the original device configuration was backed up.
Execute an ad hoc command to change the host name back to spine01.
Create a directory named config/.
Create a static configuration file named config/spine02.cfg.
Put in this file this VyOS configuration statement that sets the host name to spineB2: set system host-name spineB2.
Create a playbook named rename-spine02.yml.
Include in this playbook a task that sources configuration statements from the config/spine02.cfg file.
Perform the play in the rename-spine02.yml playbook.
If you receive an error regarding the file path, make sure you have placed spine02.cfg into the coding directory.
Execute an ad hoc command to confirm that the host name of spine02 is now spineB2.
Execute an ad hoc command to change the host name back to spine02.
Create the file host_vars/cs01/vars.yml if it does not already exist.
Add a YAML mapping to the host_vars/cs01/vars.yml file that maps the variable name new_hostname to the value csA1.
Create a Jinja2 template named ios-cs-hostname.j2 that consists of the IOS command to set the host name.
When setting the host name with Ansible, it makes sense to use the Ansible magic variable inventory_hostname, but for the purpose of this exercise, use the variable new_hostname instead.
The IOS command to set the host name is hostname .
hostname
Create a playbook named rename-cs01.yml.
The play in this playbook should contain a task that uses the ios_config module, in which the lines used by ios_config are sourced from the ios-cs-hostname.j2 template.
Perform the play in the rename-cs01.yml playbook.
Execute an ad hoc command and confirm that the host name of cs01 is now csA1.
Execute an ad hoc command to change the host name back to cs01.
This concludes the lab.