04.04.2020 Views

Mastering Ansible

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1

• Host selection for plays and tasks

• Play and task names

Order of operations

Ansible is designed to be as easy as possible for a human to understand. The

developers strive to strike the best balance between human comprehension and

machine efficiency. To that end, nearly everything in Ansible can be assumed to be

executed in a top to bottom order; that is the operation listed at the top of a file will

be accomplished before the operation listed at the bottom of a file. Having said that,

there are a few caveats and even a few ways to influence the order of operations.

A playbook has only two main operations it can accomplish. It can either run a play,

or it can include another playbook from somewhere on the filesystem. The order

in which these are accomplished is simply the order in which they appear in the

playbook file, from top to bottom. It is important to note that while the operations are

executed in order, the entire playbook, and any included playbooks, is completely

parsed before any executions. This means that any included playbook file has to exist

at the time of the playbook parsing. They cannot be generated in an earlier operation.

Within a play, there are a few more operations. While a playbook is strictly ordered

from top to bottom, a play has a more nuanced order of operations. Here is a list of

the possible operations and the order in which they will happen:

• Variable loading

• Fact gathering

• The pre_tasks execution

• Handlers notified from the pre_tasks execution

• Roles execution

• Tasks execution

• Handlers notified from roles or tasks execution

• The post_tasks execution

• Handlers notified from post_tasks execution

Here is an example play with most of these operations shown:

---

- hosts: localhost

gather_facts: false

vars:

[ 13 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!