Automation · Ansible
Error Handling
Cheat sheet · https://pcornel.dk/topic.php?topic=5418
Answer
Ansible error handling controls how failed, unreachable, changed or rescued tasks affect host progression using result conditions, blocks/rescue/always, retries and failure policy.
Remember
- ignore_errors ≠ error resolved; it only changes control flow after a failure.
- Rescue executed ≠ original desired state restored; compensation needs independent verification.
- failed_when false ≠ command succeeded; policy can reclassify a nonzero/custom result.
- Unreachable ≠ normal task failure; connection failures have distinct handling/state.
First checks
- block/rescue/always — error handling
- ignore_errors only deliberately — risk
- failed_when conditions — correct failure detection
Verify in this order
task error → rescue → cleanup/rollback → report
Where it usually breaks
Handled/ignored/rescued status proves Ansible control flow continued according to policy; it does not prove root cause fixed or target state restored.
Error Handling 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=5418