Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

Building Blocks of Ansible

Ansible is an enormously popular automation framework that has been used to automate IT operations for a long time. It simplifies the management of different infrastructure nodes and translates the business logic into well-defined procedures in order to implement this business logic. Ansible is written in Python and it mainly relies on SSH to communicate with infrastructure nodes to execute instructions on them. It started support for networking devices beginning with Ansible 1.9, and with Ansible 2.9, its current support for network devices has grown extensively. It can interact with network devices using either SSH or via API if the network vendors support APIs on their equipment. It also provides multiple advantages, including the following:

  • An easy learning curve: Writing Ansible playbooks requires knowledge of YAML and Jinja2 templates, which are easy to learn, and its descriptive language is easy to understand.
  • Agentless: It doesn't require an agent to be installed on the remotely managed device in order to control this device.
  • Extensible: Ansible comes equipped with multiple modules to execute a variety of tasks on the managed nodes. It also supports writing custom modules and plugins to extend Ansible's core functionality.
  • Idempotent: Ansible will not change the state of the device unless it needs to in order to change its setting to reach the desired state. Once it is in this desired state, running Ansible Playbooks against the device will not alter its configurations.

In this chapter, we will introduce the main components of Ansible and outline the different features and options that Ansible supports. The following are the main recipes that will be covered:

  • Installing Ansible
  • Building Ansible's inventory
  • Using Ansible's variables
  • Building Ansible's playbook
  • Using Ansible's conditionals
  • Using Ansible's loops
  • Securing secrets with Ansible Vault
  • Using Jinja2 with Ansible
  • Using Ansible's filters
  • Using Ansible Tags
  • Customizing Ansible's settings
  • Using Ansible Roles

The purpose of this chapter is to have a basic understanding of the different Ansible components that we will utilize throughout this book in order to interact with the networking device. Consequently, all the examples in this chapter are not focused on managing networking devices. Instead, we will focus on understanding the different components in Ansible in order to use them effectively in the next chapters.