- name: Get the mount point info
  ansible.builtin.set_fact:
    shrink_lv_mount_info: "{{ ansible_facts['mounts'] | selectattr('device', 'equalto', item['device']) | first }}"

- name: Assert that the mount point exists
  ansible.builtin.assert:
    that: shrink_lv_mount_info['device'] is defined
    fail_msg: "Mount point {{ item['device'] }} does not exist"

- name: Assert that the filesystem is supported
  ansible.builtin.assert:
    that: shrink_lv_mount_info['fstype'] in ['ext4']
    fail_msg: "Unsupported filesystem '{{ shrink_lv_mount_info['fstype'] }}' on '{{ item['device'] }}'"

- name: Assert that the filesystem has enough free space
  ansible.builtin.assert:
    that: shrink_lv_mount_info['block_size'] * shrink_lv_mount_info['block_used'] < (item['size'] | ansible.builtin.human_to_bytes)
    fail_msg: >
      Requested size {{ item['size'] }} is smaller than currently used
      {{ (shrink_lv_mount_info['block_size'] * shrink_lv_mount_info['block_used']) | ansible.builtin.human_readable }}
