Triggering handlers from another role

1,567 views
Skip to first unread message

Hagai Kariti

unread,
Mar 9, 2014, 11:08:04 AM3/9/14
to ansible...@googlegroups.com
Hi all,
I'm updating a service's configurations and I need to trigger a reload. Tricky thing is both services have different roles, specifically a RabbitMQ role that add a config file for Collectd. Ideally I could just notify collect'd handler, but as they are in different roles (and I would like to keep them independent) I can't be sure collectd's handler will be defined when rabbitmq's tasks are run. My instinct is that there should be a feature for making handlers from all roles globally available, or lazy-loading handlers on demand from the role path. Is there a simpler solution that currently works, though?

Thanks!

Nick Groenen

unread,
Mar 10, 2014, 12:28:54 PM3/10/14
to ansible...@googlegroups.com
On Sun, Mar 9, 2014 at 4:08 PM, Hagai Kariti <hka...@gmail.com> wrote:
> Is there a simpler solution that currently works, though?

You can include handlers from another file, the same way you can
include tasks. In your-role/handers/main.yml, you might for example
have:

- include: ../../some-other-role/handlers/main.yml

--
Nick Groenen | zoni | @NickGroenen
https://zoni.nl | GnuPG/GPG key ID: 0xAB5382F6

Michael DeHaan

unread,
Mar 10, 2014, 1:50:07 PM3/10/14
to ansible...@googlegroups.com
"My instinct is that there should be a feature for making handlers from all roles globally available"

Yep, this isn't needed as handlers are already globally accessible by name.  You can, for instance, define "restart apache" in roles/common/handlers/main.yml and reference it from other roles later on.








--
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/CAGV0WwOWeXD2VoBO9VX4ssm8eTE9MYJckzf2Aw64ob43yLU5pg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hagai Kariti

unread,
Mar 11, 2014, 9:06:44 AM3/11/14
to ansible...@googlegroups.com

On Monday, March 10, 2014 6:28:54 PM UTC+2, Nick Groenen wrote:
- include: ../../some-other-role/handlers/main.yml

That works, thanks!
Would be nice to see  a solution that uses role_path instead of assuming dir structure. 
Reply all
Reply to author
Forward
0 new messages