FreeKB - pre_tasks module
Ansible - pre_tasks module

When using the roles module, tasks will be performed in this order:

  • pre_tasks
  • If the pre_tasks include the notify module, the handlers will be run. 
  • If the role contains any dependencies, the dependencies will be run.
  • asks
  • If the tasks include the notify module, the handlers will be run. 
  • post_tasks
  • If the post_tasks include the notify module, the handlers will be run. 

Take for example the following playbook. Notice the post_tasks modules appears first, then the roles module, then the pre_tasks module. 

---
- hosts: all

  post_tasks:
    - name: this is a post task
      debug:
        msg: "this is a post task"

  roles:
    - foo

  pre_tasks:
    - name: this is a pre task
      debug:
        msg: "this is a pre task"

 

However, when this playbook is run, the pre_tasks will be invoked first, then the tasks, and finally the post tasks, like this.

TASK [this is a pre task]
ok: [server1.example.com] => {
    "msg": "this is a pre task"
}

TASK [foo : this is a task] 
ok: [server1.example.com] => {
    "msg": "this is a task"
}

TASK [this is a post task]
ok: [server1.example.com] => {
    "msg": "this is a post task"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 2b850 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |