Clone Repo:
git clone https://github.com/RayJin2000/ansible-handler-execution-order.git
Run ansible-playbook:
ansible-playbook playbooks/test.yml
Exprected Output:
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Test Handler] ***************************************************************************************************************************************************************************************************************************
TASK [role_2 : role_2 task_1] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_2 task_1"
}
TASK [role_2 : role_2 task_2] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_2 task_2"
}
TASK [role_2 : role_2 task_3] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_2 task_3"
}
TASK [role_1 : role_1 task_1] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_1 task_1"
}
TASK [role_1 : role_1 task_2] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_1 task_2"
}
TASK [role_1 : role_1 task_3] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_1 task_3"
}
TASK [role_3 : role_3 task_1] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_3 task_1"
}
TASK [role_3 : role_3 task_2] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_3 task_2"
}
TASK [role_3 : role_3 task_3] *****************************************************************************************************************************************************************************************************************
changed: [localhost] => {
"msg": "role_3 task_3"
}
RUNNING HANDLER [role_2 : role_2_handler_1] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_2_handler_1"
}
RUNNING HANDLER [role_2 : role_2_handler_2] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_2_handler_2"
}
RUNNING HANDLER [role_2 : role_2_handler_3] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_2_handler_3"
}
RUNNING HANDLER [role_1 : role_1_handler_1] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_1_handler_1"
}
RUNNING HANDLER [role_1 : role_1_handler_2] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_1_handler_2"
}
RUNNING HANDLER [role_1 : role_1_handler_3] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_1_handler_3"
}
RUNNING HANDLER [role_3 : role_3_handler_1] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_3_handler_1"
}
RUNNING HANDLER [role_3 : role_3_handler_2] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_3_handler_2"
}
RUNNING HANDLER [role_3 : role_3_handler_3] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "role_3_handler_3"
}
PLAY RECAP ************************************************************************************************************************************************************************************************************************************
localhost : ok=18 changed=9 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Tested with:
> ansible --version
ansible [core 2.16.11]
python version = 3.12.6 (main, Sep 9 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)] (/usr/bin/python3)
jinja version = 3.1.4
libyaml = True