Triggering handlers from another role

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!

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

“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.

  • 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.