Python Network Programming
上QQ阅读APP看书,第一时间看更新

The Ansible architecture

The Ansible architecture consists of playbooks, plays, and tasks. Take a look at df_playbook.yml that we used previously:

Ansible playbook

The whole file is called a playbook, which contains one or more plays. Each play can consist of one or more tasks. In our simple example, we only have one play, which contains a single task. In this section, we will take a look at the following:

  • YAML: This format is extensively used in Ansible to express playbooks and variables.
  • Inventory: The inventory is where you can specify and group hosts in your infrastructure. You can also optionally specify host and group variables in the inventory file.
  • Variables: Each of the network devices is different. It has a different hostname, IP, neighbor relations, and so on. Variables allow for a standard set of plays while still accommodating these differences.
  • Templates: Templates are nothing new in networking. In fact, you are probably using one without thinking of it as a template. What do we typically do when we need to provision a new device or replace an RMA (return merchandise authorization)? We copy the old configuration over and replace the differences such as the hostname and the loopback IP addresses. Ansible standardizes the template formatting with Jinja2, which we will dive deeper into later on.

In Chapter 8The Python Automation Framework Beyond Basics, we will cover some more advanced topics such as conditionals, loops, blocks, handlers, playbook roles, and how they can be included with network management.