handlers not being played

40 views
Skip to first unread message

Johan Söderberg

unread,
Dec 8, 2015, 9:42:13 AM12/8/15
to Ansible Project
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

James Cammarata

unread,
Dec 8, 2015, 9:57:03 AM12/8/15
to ansible...@googlegroups.com
Hi Johan, with which version of Ansible are you seeing this?

James Cammarata
Director, Ansible Core Engineering
github: jimi-c

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/444545b9-0a0e-4ccd-891c-bfef2781b735%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Söderberg

unread,
Dec 8, 2015, 10:00:58 AM12/8/15
to Ansible Project
I'm running 1.9.4 installed from the fedora epel repo.

/Johan

Johan Söderberg

unread,
Dec 15, 2015, 2:33:09 AM12/15/15
to Ansible Project
Hi James,


I'm running 1.9.4 installed from the fedora epel repo.


/Johan



Reply all
Reply to author
Forward
0 new messages