Duplicated handlers when notifying by name with var

Hi,

I’m trying to notify handlers using vars in its name. If same role is called twice with diffferent vars - handlers start duplicating.

role1/handlers/main.yml

  • name: restart var1
    shell: echo restart var1

  • name: restart var2
    shell: echo restart var2

role1/tasks/main.yml

  • shell: echo hi
    notify:
  • restart {{ var }}

playbook.yml

  • hosts: localhost
    gather_facts: no
    roles:
  • role: role1
    var: var1
  • role: role1
    var: var2

Output I get:

PLAY [localhost] **************************************************************

TASK: [shell echo hi] *********************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo hi ", “delta”: “0:00:00.161020”, “end”: “2013-08-22 23:50:00.470022”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:00.309002”, “stderr”: “”, “stdout”: “hi”}

TASK: [shell echo hi] *********************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo hi ", “delta”: “0:00:00.165521”, “end”: “2013-08-22 23:50:01.796191”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:01.630670”, “stderr”: “”, “stdout”: “hi”}

NOTIFIED: [restart var1] ******************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo restart var1 ", “delta”: “0:00:00.161521”, “end”: “2013-08-22 23:50:03.069853”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:02.908332”, “stderr”: “”, “stdout”: “restart var1”}

NOTIFIED: [restart var2] ******************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo restart var2 ", “delta”: “0:00:00.151519”, “end”: “2013-08-22 23:50:04.340014”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:04.188495”, “stderr”: “”, “stdout”: “restart var2”}

NOTIFIED: [restart var1] ******************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo restart var1 ", “delta”: “0:00:00.154520”, “end”: “2013-08-22 23:50:05.592673”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:05.438153”, “stderr”: “”, “stdout”: “restart var1”}

NOTIFIED: [restart var2] ******************************************************
changed: [192.168.33.10] => {“changed”: true, “cmd”: "echo restart var2 ", “delta”: “0:00:00.158520”, “end”: “2013-08-22 23:50:06.830330”, “item”: “”, “rc”: 0, “start”: “2013-08-22 23:50:06.671810”, “stderr”: “”, “stdout”: “restart var2”}

PLAY RECAP ********************************************************************
192.168.33.10 : ok=6 changed=6 unreachable=0 failed=0

I expect that each handler will be called only once. Having 3 role definitions will result in 9 notifications (3 per each handler)
Ansible: latest 1.3 HEAD

Is that a bug or my configuration problem?

Well a handler could be parameterized, so … it depends.

We have talked about a way for the new role dependencies to require a role that could be included only once (by some intelligence built into the meta/ information in the role) that would allow you to require some_other role that defined the handler in one place.