On 12. feb. 2017 19:15, Michael Ströder wrote:
Kai Stian Olstad wrote:
You can always create the handler in the role so you don't need to use the 
other roles
handler, that's what I do to make them independent.

I'll try explain better.

Assume a play invoking two roles A and B:

role A
  - installs pkg1 with notifying "restart srv1" in case of a package update
  - enables and initially starts service srv1
  - has handler "restart srv1" which restarts service srv1

role B
  - installs *pkg1* with notifying "restart srv2" in case of a package update
  - enables and initially starts service srv2
  - has handler "restart srv2" which restarts service srv2

When role A gets played the handler "restart srv1" will receive the 
notification of pkg1
update but in role B there will be no such pkg1 update anymore and thus no 
notification
to handler "restart srv2" and therefore srv2 continous to run based on outdated 
software
(which I'd like to avoid).

Or can I have handlers with same name "restart srv1 and srv2" in more than role 
and all
gets notified?

If you have handlers with the same name only one of them will be notified (see the note in the link bellow).
But in Ansible 2.2 notify has a listen: feature.

If you add listen: 'restart srv" to the handlers "restart srv1" and "restart srv2", then you can use notify: 'restart srv" instead and both of them will get notified.
And if you remove role A or role B it will still work.

Read more about listen: here
https://docs.ansible.com/ansible/playbooks_intro.html#handlers-running-operations-on-change

--
Kai Stian Olstad

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7b3b40b3-6169-76e3-95f0-bec06c865f56%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to