---
- name: Debug __partition_devices
  ansible.builtin.debug:
    msg: "{{ item }}1 :: {{ item | split('/') | last }}"
    verbosity: 1

- name: Creating layout for {{ item }}
  ansible.builtin.debug:
    msg: "Setting up LVM PV/VG/LVol for {{ item }}..."

- name: Create partitions on all drives
  community.general.parted:
    device   : "{{ item }}"
    number   : 1
    flags    : ['lvm']
    state    : present
    part_end : "{{ __part_size }}"

- name: Create VGs on LVM devices
  community.general.lvg:
    vg  : "{{ __vg_name }}-{{ item | split('/') | last }}"
    pvs : "{{ item }}1"

- name: Create LV
  community.general.lvol:
    vg    : "{{ __vg_name }}-{{ item | split('/') | last }}"
    lv    : "{{ __lv_name }}-{{ item | split('/') | last }}"
    size  : "{{ __lv_size }}"
    force : true

- name: Create lvol mount point
  ansible.builtin.file:
    path  : "{{ __lv_mount }}-{{ item | split('/') | last }}"
    state : directory
    mode  : "0755"

- name: Create filesystems
  community.general.filesystem:
    dev    : "/dev/{{ __vg_name }}-{{ item | split('/') | last }}/{{ __lv_name }}-{{ item | split('/') | last }}"
    fstype : "{{ __lv_fstype }}"

- name: Mount data
  ansible.posix.mount:
    path   : "{{ __lv_mount }}-{{ item | split('/') | last }}"
    src    : "/dev/{{ __vg_name }}-{{ item | split('/') | last }}/{{ __lv_name }}-{{ item | split('/') | last }}"
    fstype : "{{ __lv_fstype }}"
    state  : mounted
