Building a playbook
An Ansible playbook is the other fundamental element in Ansible that declares what actions you would like to perform on the target hosts (taken from the inventory). The format of the Ansible playbook is YAML, and it describes what to do in an ordered and repeatable manner, becoming the central tool for managing the infrastructure as code.
In this recipe, you will learn how to write an Ansible playbook and define the hosts that will be targeted. Thus, you will create a YAML file, determine the play’s general details (for example, the hosts to execute toward), and define a list of tasks.
The command to execute the playbook is ansible-playbook. It can be explicit and point to a specific inventory, via -i hosts.yml, or take the default inventory from the Ansible configuration. Finally, it takes the playbook name to execute (pb_debug_vars.yml):
root@cookbook-lab:~/cookbook-lab/chapters/ch02# vi pb_debug_vars.yml
---
- name: Initial...