Ansible - Invoking preliminary tasks using pre_tasks
by
Jeremy Canfield |
Updated: March 01 2023
| Ansible articles
tasks are performed in this order:
- pre_tasks
- tasks
- 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