Suppose you want to create a handler that restarts a service
only if it is already running.
Handlers can “listen” to generic topics, and tasks can notify those topics
as shown below. This functionality makes it much easier
to trigger multiple handlers. It also decouples handlers from their names,
making it easier to share handlers among playbooks and roles:
1
1
1
1
1
1
1
1
1
1
1 1- name: Check if restarted
2shell: check_is_started.sh
3register: result
4listen: Restart processes
5
6
7
8- name: Restart conditionally step 2
9service: name=service state=restarted
10when: result
11listen: Restart processes
1