Chapter 1 What is Network Automation?

For diagrams, tables, or exact code formatting, .

JOHN W. CAPOBIANCOPRINTED PAGE 26

Automating a mistake can arguably lead to faster impact, on a larger scale, then a mistake made manually at the CLI (a single device). For something as potentially dangerous as network automation in such a risk adverse field, check mode offers the ability to perform a dry run of a playbook without making any modifications to the network. Check mode, on its own, will show hosts in green text indicating no changes would have been made by the Ansible playbook if it was executed. Should changes be found the hosts with changes will show in yellow text. This indicates Ansible, in execute mode, would have pushed changes to the device. It also indicates the playbook is not idempotent. Results can be documented and included as artifacts in the change management approval process. Stress is reduced, and reassurance is offered further easing the transition to network automation. For all changes that cannot be performed in a lab environment or for large disruptive changes touching many devices, check mode can be used to show the exact commands the playbook will execute serially device-by-device.

ansible-playbook <playbook.yml> --check

Differentials

Differentials (-- diff) are another option for Ansible playbooks. Diff is often used in conjunction with check mode. If the Ansible module supports diff, playbooks can be executed with the option set to compare the automated configuration against the device's configuration. This is useful for before and after comparisons or to fully understand the changes the playbook would have made had it been running in execute mode.

ansible-playbook <playbook.yml> --diff

Or when combined with check mode and verbosity:

ansible-playbook <playbook.yml --check –diff -v

A detailed guide “Check Mode (“Dry Run”)” is available here:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html Verbosity

Various levels of verbosity can be set when running the playbooks to provide more details in the output from the playbook. When combined with check mode, for example, adding one level of verbosity will show potential changes in yellow text and will also output the exact text of the configurations that would be changed. Deeper levels of verbosity exist providing even more granular output. This is useful for troubleshooting playbooks.

Tags

Tags can be added to tasks within a playbook. This can help organize, group or classify tasks and is very useful for larger playbooks. Tagged tasks can be run inside a larger playbook. Conversely it is possible to run all tasks except the tagged tasks. Tags are a way to provide meta data and organizational structure to tasks.

A detailed guide to Ansible tags is available here: