Your first Network Ansible Playbook
For this challenge we will examine an already created Ansible Playbook
Ansible Network Automation Basics
The lab objective is to use Ansible Automation to update the configuration of a Cisco CSR router. This exercise will not create an Ansible Playbook, but use an existing one that has been provided.
This exercise will cover:
-
examining an existing Ansible Playbook
-
executing an Ansible Playbook on the command line using the ansible-navigator command
-
check mode (the
--checkparameter) -
verbose mode (the
--verboseor -v parameter)
Ansible Plays
-
What am I automating?
--- - name: configure network devices hosts: network become: yes -
What are they?
-
Top level specification for a group of tasks.
Will tell that play which hosts it will execute on and control behavior such as fact gathering or privilege level.
-
Building blocks for playbooks
Multiple plays can exist within an Ansible playbook
-
Ansible Modules
-
The "tools in the toolkit"
- name: ensure that the desired snmp strings are present cisco.ios.config: commands: - snmp-server community ansible-public RO - snmp-server community ansible-private RW save_when: modified -
What are they?
Parametrized components with internal logic, representing a single step to be done. The modules "do" things in Ansible.
Ansible Plugins
-
What are they?
Plugins are pieces of code that augment Ansible’s core functionality. Ansible uses a plugin architecture to enable a rich, flexible, and expandable feature set.
{{ some_variable | `to_nice_json` }} {{ some_variable | `to_nice_yaml` }}
Ansible Inventory
-
What are they?
List of systems in your infrastructure that automation is executed against
[web] webserver1.example.com webserver2.example.com [db] dbserver1.example.com [switches] leaf01.internal.com leaf02.internal.com
Lets get started
That is the end of of your lab briefing!
Step 1 - Examine Ansible Playbook
-
Open the
playbook.ymlin the code-server tab.We will explore in detail the components of an Ansible Playbook in the next exercise. It is suffice for now to see that this playbook will run two Cisco IOS-XE commands:
snmp-server community ansible-public RO snmp-server community ansible-private RW
Step 2 - Execute Ansible Playbook
-
Open the terminal tab and run the following command:
ansible-navigator run playbook.yml --mode stdout--mode stdout- By default ansible-navigator will run in interactive mode. The default behavior can be modified by modifying the ansible-navigator.yml configuration file. As playbooks get longer and involve multiple hosts the interactive mode allows you to "zoom in" on data in real-time, filter it, and navigate between various Ansible components. Since this task only ran one task on one host the stdout is sufficient.