Hi,
I have a problem where handlers not being played. I've narrowed it down to the following situation:
test.yml:
---
- hosts: test
roles:
- role: common
when: commonrole_has_run is not defined
roles/common/tasks/main.yml
---
- name: Debug common role
shell: date
notify:
- debug_handler
tags: debug
- set_fact: commonrole_has_run=true
when: commonrole_has_run is not defined
roles/common/handlers/main.yml
---
- name: debug_handler
debug: msg="debug_handler"
tags: debug
When I run the playbook test.yml:
PLAY [test] *******************************************************************
GATHERING FACTS ***************************************************************
ok: [
tst01-adm.example.com]
TASK: [common | Debug common role] ********************************************
changed: [
tst01-adm.example.com]
TASK: [common | set_fact commonrole_has_run=true] *****************************
ok: [
tst01-adm.example.com]
NOTIFIED: [common | debug_handler] ********************************************
skipping: [
tst01-adm.example.com]
PLAY RECAP ********************************************************************
tst01-adm.example.com : ok=3 changed=1 unreachable=0 failed=0
Now if I remove the set_fact from roles/common/tasks/main.yml the handler is run:
PLAY [test] *******************************************************************
GATHERING FACTS ***************************************************************
ok: [
tst01-adm.example.com]
TASK: [common | Debug common role] ********************************************
changed: [
tst01-adm.example.com]
NOTIFIED: [common | debug_handler] ********************************************
ok: [
tst01-adm.example.com] => {
"msg": "debug_handler"
}
PLAY RECAP ********************************************************************
tst01-adm.example.com : ok=3 changed=1 unreachable=0 failed=0
I hope someone can shed some light why the handler is not being played? The reason for the set_fact is to avoid the common role being run more than once in a larger site with lots of roles.
Thanks in advance,
/Johan Söderberg