Control Failure: failed_when & ignore_errors
Define what counts as a failure.
Control Failure: failed_when & ignore_errors is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
You Decide What Failure Means
Ansible fails a task on a nonzero return code, but you can override that. Two keywords let you redefine failure. 🎛️
ignore_errors Keeps Going
Set ignore_errors to true and a failed task is logged but does not stop the play. The host stays in play.
- name: Try optional cleanup
ansible.builtin.command: /opt/maybe-missing
ignore_errors: trueIt Still Shows as Failed
ignore_errors does not hide the failure; output still reads FAILED. It only stops the failure from halting later tasks.
failed_when Redefines Failure
Use failed_when to set your own failure condition. The task fails only when your expression is true.
- name: Check status
ansible.builtin.command: /opt/healthcheck
register: result
failed_when: result.rc > 1Pair with register
failed_when usually inspects a registered result: its rc, stdout or stderr. Capture output first, then judge it.
- ansible.builtin.command: grep ERROR app.log
register: out
failed_when: "'CRITICAL' in out.stdout"Never Fail This Task
Set failed_when to false and the task can never fail, even on a nonzero code. Cleaner than ignore_errors for known-noisy commands.
- ansible.builtin.command: pkill myapp
failed_when: falseMatch Multiple Conditions
failed_when can take a list of conditions joined with and, or a compound expression with or for richer rules.
failed_when:
- result.rc != 0
- "'skipped' not in result.stdout"changed_when Is a Cousin
The related changed_when controls the changed status instead of failure, useful to mark a command task as never-changed.
- ansible.builtin.command: /opt/report
changed_when: falseignore vs failed_when
Reach for failed_when when you can describe success precisely; use ignore_errors only for truly optional, best-effort steps.
Pairs Well with rescue
Instead of ignoring errors, let a real failure trigger a rescue block. You get recovery instead of a silent skip. 🤝
Both Are Per-Task
Both failed_when and ignore_errors live on a single task, not a whole play. Each task decides its own failure behavior.
Quick Check
Let us compare the two keywords.
Recap
failed_when defines exactly when a task fails, while ignore_errors lets the play continue past a failure. You own the rules. ✅
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Control Failure: failed_when & ignore_errors” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Control Failure: failed_when & ignore_errors”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Control Failure: failed_when & ignore_errors”?
Define what counts as a failure. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.
How long does the “Control Failure: failed_when & ignore_errors” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Group Tasks with block
- Try / Catch with rescue & always
- Control Failure: failed_when & ignore_errors
- Custom Assertions with the fail Module