Quiz Entry - updated: 2026.11.12
How is a task connected to its handler in a playbook?
The task lists the handler's name under notify:; the play's handlers: section defines a task with exactly that name. The name is the only link.
tasks:
- name: copy demo.example.conf configuration template
ansible.builtin.template:
src: /var/lib/templates/demo.example.conf.template
dest: /etc/httpd/conf.d/demo.example.conf
notify:
- restart apache
handlers:
- name: restart apache
ansible.builtin.service:
name: httpd
state: restarted
The parts:
- the task that notifies (here
template); notify:, saying this task can trigger handlers;- the handler name to trigger,
restart apache; handlers:, a play-level section (at the same level astasks:) that starts the list of handlers;- the handler's
name, which must match the notified name exactly; - the module the handler runs, here
servicewithstate: restarted.
Because the link is a plain string, a typo (restart Apache vs restart apache) breaks it. Ansible stops with an error that the notified handler was not found, so the mistake shows up on the first run that changes something.
Go deeper:
Handler example (official docs) โ a complete play with tasks and handlers.