DevOps Bootcamp · Lesson

Register a Result, Then Decide

Use registered output in conditions.

Lesson 4 of 413 steps

Register a Result, Then Decide is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 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.

React to What Happened

Often the next step depends on the last one. The register keyword saves a task's result so later tasks can read it. 📥

Capturing Output

Add register to store the result in a variable of your choosing. Here the command output lands in result.

- name: Check disk
  ansible.builtin.command: df -h /
  register: result

What Is Inside

A registered variable is rich. It holds rc (return code), stdout, stderr, and flags like changed and failed.

Decide on Return Code

Run a follow-up only when the previous command succeeded by checking its rc is zero.

when: result.rc == 0

Branch on changed

The changed flag tells you if the task altered the system. Trigger cleanup only when something actually changed.

when: result.changed

Search the Output

The in test scans stdout for text. This runs the next task only if the word active appeared.

when: "active" in result.stdout

Let It Fail, Then Handle

Pair register with ignore_errors so a failing task does not stop the play, letting you inspect and react afterward.

- ansible.builtin.command: /opt/check
  register: result
  ignore_errors: true

Check failed Yourself

After ignoring errors, test the failed flag to decide your own recovery path instead of crashing the play.

when: result.failed

Registered in a Loop

If the task uses a loop, the registered variable holds a results list, one entry per iteration, that you can examine.

Debug to Explore

Unsure of the shape? Print the whole variable with debug to see every key before you write your condition.

- ansible.builtin.debug:
    var: result

Capture, Then Decide

register turns a one-shot task into useful state. Capture the result, then let when steer what runs next. 🎯

Quick Check

Let us confirm how register and when work together.

Recap

Use register to save a task result, then read rc, changed, stdout or failed in a later when. ✅

Free to start

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 “Register a Result, Then Decide” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Register a Result, Then Decide”, 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 “Register a Result, Then Decide”?

Use registered output in conditions. 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 4 of 4.

How long does the “Register a Result, Then Decide” 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

  1. Run a Task Only when True
  2. Branch on OS Family Facts
  3. Combining Conditions with and / or
  4. Register a Result, Then Decide
← Back to DevOps Bootcamp