Ansible Playbooks: How Do They Work?

Ansible Playbooks: How Do They Work?

We’ve already discussed how Ansible works and its salient features. Now it’s time to shift our attention to the nitty gritty details of the software. First up, let’s take a look at Ansible playbooks.

Playbooks are the ligament holding the whole Ansible structure together. The modules in Ansible are the tools that perform the actions, while playbooks design the plan for the whole process and lay it out for the modules to follow.  In general, the playbook is the orchestration, configuration and deployment language for Ansible. Whether you need to set up steps for a particular process in your remote system or you want to enforce policies for the remote systems, without playbooks, running Ansible efficiently is unimaginable.

Listed below are the uses of playbooks and their contribution to Ansible.

  1. As discussed above, the fundamental objective of playbooks is to look after the configuration, deployment and orchestration aspects of Ansible.Having said that, playbooks play a much larger role in the overall function of Ansible.
  2. On a more advanced level, Ansible can look after rolling out updates, communicating with other hosts, rolling out action items to other hosts and managing the whole setup from a load managing standpoint.
  3. The biggest advantage with playbooks is the human readable format that it follows. As users we need little or no knowledge of programming languages to start working with playbooks, as they are written in basic text language.

How do playbooks really work?

First of all, playbooks are not designed to work as programming languages. Rather, they’re a model for a configuration or an entire process (or part of a process). They follow the YAML format, which has a minimum of syntax involved.

  1. Every playbook has ‘plays’ listed in it. The objective of the plays is to define tasks for the groups of available resources and map them.
  2. A playbook can have multiple plays with each one targeting a certain section of the whole infrastructure. Each play would then have tasks assigned to the resources as per the requirements.
  3. In cases where a play targets more than one machine or section, the user has the control over which machine to target first.
  4. The tasks in a play run one at a time and it is the job of the playbook to allot suitable resources to each task.
  5. Eventually, the goal of each task is to run a module which in turn is responsible for a certain section of the Ansible infrastructure.
  6. From a flexibility standpoint, playbooks allow support to run a task as another user, as a root user or by switching between users.

Online Technology Courses Stone River eLearning