Defining Handlers & Restart Patterns
Write reusable restart-service handlers.
Where Handlers Live
Handlers go in their own handlers section of a play, separate from your normal tasks. That keeps reactive actions clearly grouped.
tasks:
- name: Deploy config
ansible.builtin.template:
src: app.conf.j2
dest: /etc/app.conf
notify: Restart app
handlers:
- name: Restart app
ansible.builtin.service:
name: app
state: restartedA Handler Is a Task
A handler uses the exact same syntax as a task: a name and a module call. The only difference is that it waits to be notified.
All lessons in this course
- Notify a Handler on Change
- Defining Handlers & Restart Patterns
- When Handlers Run & flush_handlers
- Listen: One Trigger, Many Handlers