Interview Prep/Ansible/Ad-hoc Commands, Modules and Idempotency

How does check mode work, and which modules cannot honour it?

AdvancedConceptAd-hoc Commands, Modules and Idempotency
Answer

--check asks each module to predict what it would change without changing it. A module must declare supports_check_mode. Modules that cannot predict, notably command, shell and raw (unless creates/removes allow a decision), are skipped, so later tasks that depend on their output may break or give wrong predictions.

Per-task control exists:

- ansible.builtin.command: /opt/app/bin/version
  register: ver
  check_mode: false      # always run, even under --check
  changed_when: false

check_mode: true on a task forces a dry run for just that task. Combine with --diff to see file content changes. Check mode is a good guard, but never treat it as a guarantee of the real result.

All Ansible questions Roadmap: Ansible

More on Ad-hoc Commands, Modules and Idempotency