Bootstrap FreeKB - Ansible - Invoking preliminary tasks using pre_tasks
Ansible - Invoking preliminary tasks using pre_tasks

Updated:   |  Ansible articles

tasks are performed in this order:

  1. pre_tasks
  2. tasks
  3. post_tasks

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"
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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