In this lab, you will execute ad hoc commands and run plays.
Outcomes
You should be able to execute ad hoc commands and run plays in playbooks.
This exercise assumes you know how to set the value of variables to support connection and authentication, as described in the Sectionthe section called “Lab: Running Commands and Plays” exercise.
Open a terminal window on the workstation VM and change to your ~/proj/ directory.
The ~/proj/ directory should contain a suitable hosts inventory file.
It should also include group variables files under group_vars/ that set variables that play key roles in connecting and authenticating to remote hosts:
ansible_connection: network_cli in group_vars/network
ansible_network_os: vyos and ansible_user: vyos in group_vars/vyos
ansible_network_os: ios, ansible_user: admin in group_vars/ios
The SSH password for the cs01 device is student.
Procedure 2.3. Instructions
Execute ad hoc commands to find out if the utility and tower machines are reachable from cs01.
The IPv4 addresses of utility and tower are 172.25.250.8 and 172.25.250.9.
Hint: cs01 is an IOS device, so investigate the ios_ping module.
Create a playbook in your Ansible project directory, named iosping2.yml, that does what you did with ad hoc commands in the previous step.
Run the play in your playbook using the ansible-playbook command.
Provide student when prompted for a password.
Create a playbook that checks key system indicators, but for all devices on the network.
What are “key system indicators?”
They are the commands that you would use on the command line of a network device to check its health status.
All of those can be automated as tasks within Ansible Playbooks.
Most can probably be executed remotely as an Ansible ad hoc command.
For convenience and as an illustration, it is suggested to display at least the host name, uptime, domain name, and system time.
Use the vyos_pass and ios_pass extra command-line variables method, as shown earlier in this document, to set the ansible_pass variable to different values.
Create a file named multi-vendor-syscheck.yml with content similar to the following:
---
- name: back up config and inspect health on vyos
hosts: vyos
vars:
ansible_password: "{{ vyos_pass }}"
tasks:
- name: backup config
vyos_command:
commands:
- sh host name
- sh system uptime
- sh host domain
- sh host date
- sh host os
register: results
- name: show results
debug:
var: results.stdout
- name: back up config and inspect health on ios
hosts: ios
vars:
ansible_password: "{{ ios_pass }}"
tasks:
- name: backup config
ios_config:
backup: yes
- name: look at system elements
ios_command:
commands:
- sh ver | include uptime
- sh ip domain
- sh clock
- sh ip name-server
register: results
- name: show results
debug:
var: results.stdout
Run the play in your playbook using the ansible-playbook command.
This concludes the lab.