When a task should run only when a change is made on a machine — for example, restarting a service only if a task updated that service's configuration — Ansible uses handlers, which are tasks that run only when notified. Tasks instruct one or more handlers to execute using the notify keyword, which accepts a list of handler names or a single string; handlers run on task change, after all tasks are completed in the play. Handlers execute in the order they are defined in the handlers section, not in the order listed in the notify statement. Notifying the same handler multiple times results in the handler executing only once, regardless of how many tasks notify it — if multiple tasks update a configuration file and notify a handler to restart Apache, Ansible bounces Apache once to avoid unnecessary restarts. Tasks can also use loops to notify handlers, which is useful with variables for dynamic notifications; with a loop, the changed state is set if any of the loop items changed, so any change triggers all of the handlers. Scope: Ansible. Reviewed October 4, 2026.
Handlers: running operations on change
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- docs.ansible.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.