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.
More on Ad-hoc Commands, Modules and Idempotency
What is an ad-hoc command and what is its syntax?BeginnerWhat does `ansible all -m ping` actually test?BeginnerGive practical use cases for ad-hoc commands.IntermediateWhat is the difference between the `command` and `shell` modules?BeginnerCompare `raw`, `command`, `shell` and `script`.IntermediateWhy prefer a dedicated module over `shell`/`command`?Beginner