There is at least two ways to achieve this; and it's not clear to me what the best practice is.
Solution 1
One recommended practice is to create a file only for handlers, and include or import it in your playbook (see the differences); that way, all the roles can benefits.
For instance, let's say you have a file myhandlers.yml
with inside one handler to restart apache, and another one to reload mysqld.
Then, in your playbook:
- name: Testing 123
hosts: localhost
handlers:
- name: Here are my custom common handlers
# You can also look at include_tasks: handlers.yml
import_tasks: handlers.yml
tasks:
- command: "true"
notify: restart-apache
- command: "true"
notify: restart-mysql
Solution 2
Another clean approach is to create a dedicated role (roles/myhandlers/
for instance), and make this role a depedencies for all the others roles.
dependencies:
- myhandlers
More info on dependencies here.