Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Handlers

Direct answer

Ansible handlers are deferred tasks normally notified by changed tasks and executed later at defined flush points, allowing expensive restart/reload actions to occur only when notifications are queued.

When to use this

Use it when configuring, checking or troubleshooting Handlers in Ansible.

First 30 seconds

1. Handlers run once at end of play when notified.

2. Use for restarts/reloads.

3. flush_handlers to run earlier.

4. Names must match.

5. Avoid restarts when nothing changed.

Operational verification

task changed → notify → handler runs once

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Ansible automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformAnsible automation · Handlers owns Ansible notification/deferred execution semantics. Service internals remain in target domains.
Scope / prerequisiteUse it when configuring, checking or troubleshooting Handlers in Ansible.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

4 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

notifying task → changed status → notification queue/name resolution → handler flush → handler action → service readiness

Healthy evidence: notification source and handler identity are explicit, flush occurs as expected and service readiness is independently confirmed.

Step 2 Failure modes and next checks Narrow the fault

Suspicious evidence: name mismatch, notifier never changed, prior failure suppressing handlers, unexpected flush timing or assuming restart command success equals health.

Handler success shows the deferred Ansible action ran, but it does not show the service reached application-ready state.

Step 3 Common mistakes Narrow the fault
  • Expecting handlers to run when a play fails earlier (use --force-handlers or meta: flush_handlers).
  • Handler names that do not match notify.
Step 4 Where it fails Narrow the fault

Where Handlers usually goes wrong: notification identity, deferred execution, deduplication and service-state verification.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Task changed ≠ handler executed; notification, later failure or play flow can prevent execution.
  • Handler notified multiple times ≠ handler runs multiple times by default; notifications are commonly coalesced.
  • Handler task success ≠ application ready after restart/reload.
  • No change ≠ no reload needed necessarily; out-of-band drift may exist outside notifier semantics.
Key checks
  • notify: and handlers — restart on change
  • ansible-playbook site.yml --force-handlers — run handlers on failure
  • meta: flush_handlers — ordering
ReferenceWhat it is1 section · depth on demand

Core model

Trace notifier result, exact handler name/listen relationship, queue/deduplication, failure state and flush timing before assuming a reload/restart occurred.

ReferenceImportant terms & boundaries2 sections · depth on demand

What this shows and what it does not

Handler success shows the deferred Ansible action ran, but it does not show the service reached application-ready state.

In depth

Handlers are tasks that run only when notified by another task that reported changed, typically to restart or reload a service after its configuration changed. They run once at the end of the play, even if notified several times.

tasks:
  - name: Deploy nginx config
    ansible.builtin.template: { src: nginx.conf.j2, dest: /etc/nginx/nginx.conf, validate: 'nginx -t -c %s' }
    notify: reload nginx
handlers:
  - name: reload nginx
    ansible.builtin.service: { name: nginx, state: reloaded }

Use ansible.builtin.meta: flush_handlers when a later task needs the restart to have happened already. If a play fails before the end, pending handlers do not run unless --force-handlers is used.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docAnsible automation current

Authoritative/upstream documentation reviewed for bounded claims in Ansible > Handlers. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
ansible handlernotify handlerlisten handlerflush handlers
Embedded reference data

Quick lookup tables

Handlers Ansible boundary map

Fast input/selection, execution/result and target-proof boundaries for Handlers.

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen Ansible status treated as end-to-end acceptance
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For Handlers, rely on structured fields and stable IDs (notification identity, deferred execution, deduplication and service-state verification) rather than text formatted for display.

Confirmation

Confirm action

Continue?