--- - name: Ensure LVM is installed. package: name: - lvm2 - parted state: present # This should be the way, as it is not possible with cloudinit ... - name: Copy lvm volume detector script copy: src: setup_lvm_devices.sh dest: /usr/local/sbin/setup_lvm_devices.sh mode: "755" - name: Ensure presence of all VG community.general.lvg: vg: "{{ vg }}" pvs: "{{ pvs }}" pvresize: true state: "{{ state }}" loop: "{{ disks_vg }}" vars: state: "{{ item.state | default('present') }}" vg: "{{ item.vg }}" # pvs: "{{ ['/dev/disk/by-id/lvm-pv-uuid-']|product(item.devices_id) | map('join') | join(',') }}" pvs: "{{ item.devices_dev | join(',') }}" ignore_errors: "{{ ansible_check_mode }}" - name: Create logical volumes community.general.lvol: vg: "{{ vg }}" lv: "{{ lv }}" size: "{{ size }}" shrink: false state: "{{ state }}" loop: "{{ disks_lv }}" vars: state: "{{ item.state | default('present') }}" lv: "{{ item.lv }}" vg: "{{ item.vg }}" size: "{{ item.size }}" ignore_errors: "{{ ansible_check_mode }}" - name: Create file systems community.general.filesystem: fstype: "{{ fstype }}" dev: "{{ dev }}" resizefs: false force: false state: "{{ state }}" loop: "{{ disks_lv }}" vars: state: "{{ item.state | default('present') }}" fstype: "{{ item.fstype | default('ext4') }}" dev: "/dev/{{ item.vg }}/{{ item.lv }}" size: "{{ item.size | default ('1G') }}" ignore_errors: "{{ ansible_check_mode }}" - name: Mount file systems ansible.posix.mount: path: "{{ path }}" src: "{{ src }}" fstype: "{{ fstype }}" # opts: ro,noauto state: "{{ state }}" loop: "{{ disks_lv }}" vars: state: "{{ ( item.state == 'present' ) | ternary( 'mounted', item.state | default('mounted')) }}" fstype: "{{ item.fstype | default('ext4') }}" src: "/dev/{{ item.vg }}/{{ item.lv }}" path: "/{{ item.lv | replace('_', '/') }}" ignore_errors: "{{ ansible_check_mode }}"