LOGBOOK

HELP

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.

Two ways to reuse a handler file: notify the include_tasks handler by its own name and all tasks in the file run; or import the file and notify the individual handler tasks by their 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 services with include_tasks: restarts.yml. The tasks inside don't exist until the include runs, so notify: Restart apache finds nothing. You notify Restart 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, so notify: Restart apache triggers just that one.

The rule follows from static vs dynamic: Ansible can only find handler names that exist when the play starts.

Go deeper:

From Quiz: ITIA / Ansible: Complex Playbooks with Imports and Includes | Updated: Nov 26, 2026