2

I have an ansible playbook for some init services that are broadly similar with a few tweaks. In the top-level playbook, I include the role twice, like

   roles:
     - {role: "my-service", service: webserver}
     - {role: "my-service", service: scheduler}

the my-service role has tasks, which write init scripts, and handlers, which (re)start the service. tasks/main.yml looks like this:

- name: setup init scripts
  template: src=../../service-common/templates/my-service.conf dest=/etc/init/my-{{ service }}.conf
  notify:
    - restart my service

and handlers/main.yml has this content:

- name: restart my services
  service: name=my-{{ service }} state=restarted

But after the playbook runs, we're left with only the webserver service running, and the scheduler is stop/waiting. How can I make the handler see these as two separate notifications to be handled?

  • Bruce already explained the problem. For a solution you might have a look at this github issue: https://github.com/ansible/ansible/issues/4853 - Don't know if this now is possible or not. The last comment was a user tested it and it was not working. – udondan Feb 17 '16 at 00:58

1 Answers1

1

The Ansible documentation states:

Handlers are lists of tasks, not really any different from regular tasks, that are referenced by a globally unique name.

So it doesn't make use of any parameters, variables, etc. when determining when/how to invoke a handler. Only the name is used.

Bruce P
  • 19,995
  • 8
  • 63
  • 73