The tasks you've listed involve creating a logical volume, formatting it, creating a mountpoint, and mounting it. When running in check mode (--check), these tasks may fail or behave unexpectedly because:
1. community.general.lvol Module
The lvol module supports check mode. It will report what changes would be made without actually creating the logical volume. However, if the logical volume doesn't exist yet, subsequent tasks (like filesystem and mount) might fail because they depend on the LV existing.
2. community.general.filesystem Module
The filesystem module supports check mode. It will check if the filesystem exists and report a change if it needs to be created. However, if the logical volume doesn't exist (because lvol is in check mode and didn't create it), this task will fail with an error like:
"msg": "Device /dev/.../k3s-data-lv not found."
3. ansible.builtin.file Module
The file module supports check mode. It will report if the directory needs to be created. This task should work fine in check mode.
4. ansible.posix.mount Module
The mount module supports check mode. It will check if the filesystem is mounted and report a change if it needs to be mounted. However, if the filesystem doesn't exist (because filesystem failed), this task will fail.
Why Check Mode Fails
The main issue is that the tasks are dependent on each other, and check mode doesn't actually create the resources. To fix this, you can:
- Use
when: not ansible_check_mode to skip tasks that depend on resources created in previous tasks.
- Reorder or restructure tasks to minimize dependencies in check mode.
Example Solution
You can conditionally skip tasks that depend on the logical volume being created:
- 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
- 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
- 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
when: not ansible_check_mode