So we've mentioned playbooks quite a few times now,
so let's just jump into exactly what they are.
So an Ansible Playbook can have multiple plays that can exist within a
single playbook and can execute on different managed assets.
So an Ansible play is all about what am I automating,
and then it connects to the hosts to perform certain actions.
So each playbook comprises of one or more plays in a list.
So the goal of a play is to map a group of hosts to some well‑defined
roles represented by things Ansible calls tasks.
So at a very basic level,
a task is nothing more than a call to an Ansible module.
By composing a playbook of multiple plays,
it is now possible to orchestrate multi‑machine deployments.
So once a playbook is passed and the hosts are determined,
Ansible is now ready to execute the tasks. Tasks will include a name, a module
reference, a module argument, and task control directives.
So task execution by default is a sense that Ansible executes each task in
order one at a time against all machines by a host pattern.
Each task executes a module, and this module can have specific arguments. You
could, if you want , have a start‑at‑task task name flag,
and this will tell Ansible playbook to start the
playbook at this point in the play.
So as you know now,
a play contains a list of tasks. Tasks are executed in order
one at a time against all machines matched by a host pattern
before moving to the next task.
It is really important to understand within the play,
all hosts will get the same task directives.
So the purpose of the play is to map a selection of hosts to tasks.
So you may be thinking, well, what happens with host failure? So when
a task has been executed on all target machines,
Ansible moves to the next task.
You can use strategies to change this default behavior,
such as if a task fails on a host Ansible takes that host out of
rotation for maybe the rest of the playbook.
So you know that the goal of each task is to execute a module,
and this can have very specific arguments.
We can now include things like variables. That can bring a
lot more granularity to the playbook.
So consider that the play are a top‑level specification for a
group of tasks. A play will tell which host it will execute on
providing a host name or a group of hosts,
such as the web servers to run on.