Quiz Entry - updated: 2026.11.12
When does a notified handler run, and how many times does it run if several tasks notify it?
Once, after all the tasks of the play's tasks section have finished, no matter how many tasks notified it.
Handlers don't run at the moment they are notified. Ansible collects the notifications and runs the queued handlers in a batch at the end of the section. Five tasks each changing a part of Apache's configuration and each notifying restart apache produce one restart at the end, not five, which is exactly what you want for a service.
Two details:
- A handler that is never notified does not run at all.
- "At the end of the play" has small exceptions. Handlers are flushed after each of the sections
pre_tasks,roles/tasksandpost_tasks, and a taskansible.builtin.meta: flush_handlersruns the queued handlers immediately, for example when a later task needs the restarted service. After a flush, a handler can be notified and run again later in the play.
Go deeper:
Controlling when handlers run (official docs) — the flush points and
meta: flush_handlers.ansible.builtin.meta module (official docs) —
flush_handlersand the other meta actions.