When using the roles plugin, tasks will be performed in this order:
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"
}