Automation
Error Handling
Cheat sheet · https://pcornel.dk/topic.php?topic=5971
Answer
Error handling in automation decides what happens when a step fails: fail fast or continue, retry with backoff, time out, clean up, report clearly and leave systems in a known state.
Remember
- Fail fast on serious errors.
- Retry only operations that are safe to repeat.
- Always clean up and report clearly.
First checks
- Error classification (retryable vs fatal) — handling
- Non-zero exit and clear message on failure — signal
- Cleanup on every exit path — safety
Verify in this order
error → classify → retry/fail → cleanup → report
Where it usually breaks
Automation/controller success is not target-state proof; target config/state is not effective-runtime proof; effective state is not workload proof.
→ Error Handling · operational reference
| Layer | Error Handling operational reference |
|---|---|
| Runtime/ownership | Automation error-handling patterns / Ansible current · identify controller/worker/target ownership before mutation |
| Persistent intent | Versioned configuration/playbook/workflow with explicit dependencies and least-privilege identity |
| Verification | ansible-playbook playbook.yml --check -vv; echo exit=$? |
| Expected interpretation | Failures are classified by boundary, retries are bounded, cleanup/compensation is explicit, and automation returns an outcome that callers can distinguish from partial success. |
| Recovery boundary | Preserve correlation IDs + pre-state, then verify target/service independently after remediation |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5971