Automation · Ansible
Handlers
Cheat sheet · https://pcornel.dk/topic.php?topic=5407
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.
Remember
- 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.
First checks
- notify: and handlers — restart on change
ansible-playbook site.yml --force-handlers— run handlers on failure- meta: flush_handlers — ordering
Verify in this order
task changed → notify → handler runs once
Where it usually breaks
Handler success proves the deferred Ansible action ran; it does not prove the service reached application-ready state.
Handlers Ansible boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5407