Chapter 1 What is Network Automation?
For diagrams, tables, or exact code formatting, .
group and host variables, tasks, and playbooks are written in YAML format. VS Code has YAML extensions to help write proper YAML code while modeling the network or writing Ansible playbooks.
Jinja2
Jinja2 (http://jinja.pocoo.org/) (https://github.com/pallets/jinja/), created by Armin Ronacher in 2008, is a full featured templating engine for Python. Ansible templates will be written in Jinja2 syntax. Templates are made up of a combination of static text, dynamic variables, and programmatic logic.
Playbooks
Ansible playbooks are written in YAML. Playbooks are executed against devices in the inventory file. For full configuration management, it is required that group variables, host variables, templates, and tasks be developed in addition to the inventory file. To run an Ansible playbook, execute the following command in the Linux host:
ansible-playbook <filename.yml>
Idempotency
Idempotency is a key feature of Ansible. To be idempotent means the same task can be executed a single or multiple (infinite) times and the results will always be the same. To say the network is idempotent means the source of truth (including the results from the Ansible playbook), and the running- configuration of a device, match when compared. Once idempotent, Ansible playbooks will show the results of the playbook in green text, indicating no changes will be made because the two configurations are identical. If the configurations are not idempotent, the Ansible playbook will show a change in yellow text, reporting a change will be made by the playbook.
By reaching full coverage of the network configurations and transforming the configurations to code the master branch becomes a full representation of the network. All future changes become extremely easy to validate using the branching strategy of a working branch per change. These working branches can be executed in check mode.
Check Mode
Ansible playbooks have a check mode where playbooks can be tested without executing any changes. The combination of idempotency and check mode is very powerful.
Ideally: Make code change. Run code in check mode with verbosity enabled. Confirm exact change reflected in output of check mode. Run code in execute mode. Re-run play in check mode to confirm play results are in green text indicating no changes will be made and that the automated configuration matches the running-configuration.
