Could you give a full list of modules, which don't handle check mode explicitly?
- User
Could you give a full list of modules, which don't handle check mode explicitly?
Assistant
Ansible Modules That Don't Handle Check Mode Well
Ansible modules fall into different categories regarding check mode support. Here's a comprehensive list of modules that either don't support check mode or have limited support:
Command Execution Modules
These modules can't predict their outcome without actually running:
ansible.builtin.commandansible.builtin.shellansible.builtin.rawansible.builtin.scriptansible.builtin.expect
API and Service Interaction
uri- Cannot predict API responses- Many cloud provider modules (portions of AWS, Azure, GCP modules)
docker_container(when creating containers)k8smodules (many operations)
Database Modules
mysql_query/postgresql_query- Can't predict query outcomesmongodb_*modules - Many operationselasticsearch_*modules
Network Modules
- Many
*_commandnetwork modules - Certain operations in
ios_*,junos_*,eos_*modules
System Modules
rebootpackage_factssetup(gathers facts regardless of check mode)service_facts
File Operations (Special Cases)
fetch- Reads but doesn't modify remote systemsfind- Only gathers informationstat- Only reports file information
Other Notable Modules
pause/wait_for- Time-based operationsassert- Tests conditions but doesn't change statefail- Task failure testinginclude_*/import_*- Dynamic inclusionsset_fact/set_stats- Variable manipulationdebug- Information display only
Custom/Third-Party Modules
- Many custom or third-party modules may not implement check mode properly
How to Handle These Modules
When using these modules in playbooks that may run in check mode:
- name: Run a command that can't be checked ansible.builtin.command: "critical_operation.sh" check_mode: no # Will run even in check mode # OR when: not ansible_check_mode # Will skip in check modeYou can also add check mode support for command/shell modules with
changed_when:- name: Check if service needs restart ansible.builtin.command: "systemctl status myservice" register: service_status changed_when: "'active (running)' not in service_status.stdout" check_mode: no # Only gather infoNote that Ansible continues to improve check mode support with each release, so this list may change over time.
- User
Why do check mode fail with following Ansible tasks?
- name: Create logical volume on system disk for K3s data
community.general.lvol:
vg: "{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}"
lv: "k3s-data-lv"
size: "{{ k3s.storage.data_size }}"
force: false # never shrink (or remove)
- name: Format logical volume on system disk for K3s data community.general.filesystem: fstype: ext4 dev: "/dev/{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}/k3s-data-lv"
- name: Create mountpoint of logical volume for K3s data ansible.builtin.file: path: "/k3s-data" state: directory mode: "0755"
- name: Mount logical volume for K3s data ansible.posix.mount: path: "/k3s-data" src: "/dev/{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}/k3s-data-lv" fstype: ext4 state: mounted
- name: Create logical volume on system disk for K3s data
community.general.lvol:
vg: "{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}"
lv: "k3s-data-lv"
size: "{{ k3s.storage.data_size }}"
force: false # never shrink (or remove)
Assistant
Why These Tasks Fail in Check Mode
Your tasks are failing in check mode because they form a dependency chain where each task depends on the previous one actually creating resources. When running in check mode, those resources aren't created, causing subsequent tasks to fail.
The Specific Issues
-
community.general.lvol(Create logical volume):- In check mode, this verifies if creation is needed but doesn't actually create the logical volume
- The module tries to determine if changes are needed, but the device path doesn't exist yet
-
community.general.filesystem(Format LV):- Fails because it's trying to check a device that doesn't exist in check mode
- The previous task didn't actually create the logical volume
-
ansible.posix.mount(Mount):- Fails when validating the device path which wasn't created during check mode
How to Fix This
The solution is to add appropriate handling for check mode. Here's how to fix your playbook:
- name: Create logical volume on system disk for K3s data community.general.lvol: vg: "{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}" lv: "k3s-data-lv" size: "{{ k3s.storage.data_size }}" force: false register: lv_created - name: Format logical volume on system disk for K3s data community.general.filesystem: fstype: ext4 dev: "/dev/{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}/k3s-data-lv" when: not ansible_check_mode or lv_created is not changed - name: Create mountpoint of logical volume for K3s data ansible.builtin.file: path: "/k3s-data" state: directory mode: "0755" # This should work fine in check mode - name: Mount logical volume for K3s data ansible.posix.mount: path: "/k3s-data" src: "/dev/{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}/k3s-data-lv" fstype: ext4 state: mounted when: not ansible_check_mode or lv_created is not changedAlternative Approach
If you need to validate more thoroughly during check mode, consider:
- name: Check if LV exists command: lvs "{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}/k3s-data-lv" register: lv_check failed_when: false changed_when: false check_mode: no # Always run this check - name: Create logical volume on system disk for K3s data community.general.lvol: vg: "{{ ansible_distribution|lower + '-vg' | default('ubuntu-vg') }}" lv: "k3s-data-lv" size: "{{ k3s.storage.data_size }}" force: false register: lv_created # Continue with subsequent tasks with proper when conditionsThis approach lets you accurately determine the starting state even in check mode.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.