Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of executing roles, tasks, pre_tasks, post_task. Can tasks be defined in playbook?

Tags:

ansible

task

In playbook we can define roles, pre_tasks, post_tasks.
Can we also define tasks ? And second question is about order of executing these things. I know that order is following: pre_tasks -> roles -> post_tasks.
However, when tasks are executed?

like image 835
newbie Avatar asked Apr 05 '18 18:04

newbie


People also ask

In which order are tasks in a playbook executed?

Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.

In which order do tasks execute inside plays or roles?

When you execute a playbook, in each play, all roles will be executed first, followed by the tasks, top down in the order that they are written.

How do you define a role in Ansible playbook?

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules. In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.

What is the difference between a playbook and a role?

Role is a set of tasks and additional files to configure host to serve for a certain role. Playbook is a mapping between hosts and roles.


1 Answers

Here it is: http://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html?#using-roles

  1. Any pre_tasks defined in the play.
  2. Any handlers triggered so far will be run.
  3. Each role listed in roles will execute in turn.
  4. Any role dependencies defined in the roles meta/main.yml will be run first, subject to tag filtering and conditionals.
  5. Any tasks defined in the play.
  6. Any handlers triggered so far will be run.
  7. Any post_tasks defined in the play.
  8. Any handlers triggered so far will be run.
like image 66
Konstantin Suvorov Avatar answered Oct 16 '22 22:10

Konstantin Suvorov