Quiz Entry - updated: 2026.11.26
How do handlers work with included and imported task files?
notify can't reach a handler that is defined inside an included file. If the handler itself is an include, notifying it by name runs every task in the file. With an import, you notify the individual imported handler tasks by their own names.
* Notify the include by its own name, or notify the imported handler tasks by theirs. *
A handler is a task that only runs when something notifies it. Say restarts.yml contains two handlers, "Restart apache" and "Restart mysql":
- Included handler.
handlers: - name: Restart serviceswithinclude_tasks: restarts.yml. The tasks inside don't exist until the include runs, sonotify: Restart apachefinds nothing. You notifyRestart services, and then all tasks in the file run. - Imported handler.
handlers: - import_tasks: restarts.yml. During parsing, the two handlers become real handlers in the play, sonotify: Restart apachetriggers just that one.
The rule follows from static vs dynamic: Ansible can only find handler names that exist when the play starts.
Go deeper:
Includes and imports in handlers (official docs) — how notify behaves for included and imported handler files.
Reusing tasks as handlers (official docs) — the restarts.yml example with both ways of triggering.