DevOps Bootcamp · Lesson

Support Check Mode in Your Module

Make custom code dry-run safe.

Lesson 4 of 413 steps

Support Check Mode in Your Module 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.

What Check Mode Is

With check mode, users run a playbook using --check to preview changes. Nothing is actually modified on the host.

ansible-playbook site.yml --check

Your Module Must Opt In

Check mode is not automatic. You declare support so Ansible knows your module promises to make no changes in this mode.

Declare It on AnsibleModule

Set supports_check_mode=True when you build the module. That flag tells Ansible your code respects dry-run requests.

module = AnsibleModule(
  argument_spec=spec,
  supports_check_mode=True)

Read module.check_mode

At runtime, inspect module.check_mode. It is True when the user passed --check, and you branch your logic on it.

if module.check_mode:
    module.exit_json(changed=True)

Compute, Do Not Apply

In check mode you still compute whether a change is needed. You just stop before writing anything to the system.

Report the Would-Be Change

Exit early with the correct changed value so the dry-run preview is honest, even though nothing happened.

if module.check_mode:
    module.exit_json(changed=needs_change)

Reads Are Always Safe

Gathering current state is fine in check mode, since reading changes nothing. Only the write step must be skipped.

Forgetting It Is Dangerous

If you skip check mode support, your module may still modify the host during a dry run. That betrays the user's expectation.

Mirror Real-Run Logic

The change detection in check mode should match a normal run exactly. A wrong preview is worse than no preview at all.

Test Both Paths

Run your module with and without --check. Confirm the dry run reports the same changed result yet leaves the system untouched.

Check Mode Builds Trust

A module that honors check mode lets teams preview safely before applying. That polish is what separates toy modules from production ones.

Quick Check

Recall the two things check mode support requires from your module.

Recap

Pass supports_check_mode=True, branch on module.check_mode, compute the change but skip the write, and report changed honestly. Now your module is dry-run safe. 🔍

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 “Support Check Mode in Your Module” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Support Check Mode in Your Module”, 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 “Support Check Mode in Your Module”?

Make custom code dry-run safe. 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 “Support Check Mode in Your Module” 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. When to Build a Custom Module
  2. AnsibleModule & Argument Spec
  3. Return JSON & Honor changed
  4. Support Check Mode in Your Module
← Back to DevOps Bootcamp