Use it when configuring, checking or troubleshooting Error Handling in Ansible.
Error Handling · Ansible
Ansible error handling controls how failed, unreachable, changed or rescued tasks affect host progression using result conditions, blocks/rescue/always, retries and failure policy.
1. Handle errors with block/rescue/always.
2. failed_when to define failure precisely.
3. any_errors_fatal for critical plays.
4. Avoid blanket ignore_errors.
5. Notify on failures.
task error → rescue → cleanup/rollback → report
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
raw action result → Ansible failure/change classification → retry/block/rescue/ignore policy → continued/aborted host flow → target recovery verification
Healthy evidence: raw failure is preserved, handling policy is intentional, recovery actions are bounded and target state/original test confirms closure.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: swallowed errors, overbroad ignore_errors, false failed_when logic, endless retries, rescue without verification or treating continued play as success.
Handled/ignored/rescued status shows Ansible control flow continued according to policy, but it does not show root cause fixed or target state restored.
Step 3 Common mistakes Narrow the fault
ignore_errors: truehiding real failures.- No
rescuefor cleanup.
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.
- 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.
- block/rescue/always — error handling
- ignore_errors only deliberately — risk
- failed_when conditions — correct failure detection
ReferenceWhat it is1 section · depth on demand
Core model
Start from raw result fields and the first failing action, then evaluate failed_when/changed_when, ignore_errors, block/rescue flow and play-wide failure settings without confusing continued execution with successful remediation.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Root-cause troubleshooting remains with the first failed underlying boundary.
In depth
Error handling in Ansible decides what happens when a task fails: by default the host stops and others continue. Playbooks can change that per task or per play.
| Mechanism | Effect |
|---|---|
ignore_errors: true | Continue despite failure (use rarely) |
failed_when: | Define your own failure condition |
changed_when: | Control change reporting |
block / rescue / always | Try/catch/finally for task groups |
any_errors_fatal: true | Stop all hosts on first failure |
max_fail_percentage | Stop when too many hosts fail |
- block:
- cisco.ios.ios_config: { src: new.cfg }
- ansible.builtin.import_tasks: verify.yml
rescue:
- cisco.ios.ios_config: { replace: config, src: "backup/{{ inventory_hostname }}.cfg" }
- ansible.builtin.fail: msg="Change rolled back on {{ inventory_hostname }}"
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Error Handling. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%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.
Quick lookup tables
Error Handling Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Error Handling.
| 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 |