0Pricing
Ansible Academy · Lesson

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: restarted

A 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

  1. Notify a Handler on Change
  2. Defining Handlers & Restart Patterns
  3. When Handlers Run & flush_handlers
  4. Listen: One Trigger, Many Handlers
← Back to Ansible Academy