diff --git a/check_device2.yml b/check_device2.yml new file mode 100644 index 0000000..754a6ec --- /dev/null +++ b/check_device2.yml @@ -0,0 +1,29 @@ +--- +- name: Something + hosts: bigboot + become: false + gather_facts: true + + vars: + shrink_lv_devices: + - device: "/dev/mapper/system-root" + size: 81229615104 + + tasks: + - name: Get the mount point info + ansible.builtin.set_fact: + shrink_lv_mount_info: "{{ ansible_facts.mounts | selectattr('device', 'equalto', shrink_lv_devices[0].device) }}" + + - name: Debug shrink_lv_mount_info + ansible.builtin.debug: + var: shrink_lv_mount_info + + # - name: Assert that the mount point exists + # ansible.builtin.assert: + # that: (shrink_lv_mount_info | length) >= 1 + # fail_msg: "Mount point {{ shrink_lv_devices[0].device }} does not exist" + + # - name: Assert that the filesystem is supported + # ansible.builtin.assert: + # that: shrink_lv_mount_info[0].fstype in ['ext4'] + # fail_msg: "Unsupported filesystem '{{ shrink_lv_mount_info[0].fstype }}' on '{{ shrink_lv_devices[0].device }}'" diff --git a/check_device3.yml b/check_device3.yml new file mode 100644 index 0000000..105040f --- /dev/null +++ b/check_device3.yml @@ -0,0 +1,29 @@ +--- +- name: Something + hosts: bigboot + become: false + gather_facts: true + + vars: + shrink_lv_devices: + - device: "/dev/mapper/system-root" + size: 81229615104 + + - device: "/dev/mapper/system-home" + size: 21536149506 + + tasks: + - name: Retrieve mount points + ansible.builtin.setup: + gather_subset: + - "!all" + - "!min" + - mounts + + - name: Debug mounts + ansible.builtin.debug: + var: ansible_facts['mounts'] + + - name: Check if device has shrunken successfully + ansible.builtin.include_tasks: tasks/check_if_shrunk.yml + loop: "{{ shrink_lv_devices }}" diff --git a/hosts b/hosts index 9ac9759..182c2d7 100644 --- a/hosts +++ b/hosts @@ -1,16 +1,16 @@ [bigboot] -bigboot-test-custom-1 ansible_host=10.10.42.5 +# bigboot-test-custom-1 ansible_host=10.10.42.5 # bigboot-test-custom-2 ansible_host=10.10.42.13 # bigboot-test-custom-4 ansible_host=10.10.42.15 -bigboot-test-custom-5 ansible_host=10.10.42.16 +# bigboot-test-custom-5 ansible_host=10.10.42.16 bigboot-test-custom-6 ansible_host=10.10.42.1 -bigboot-test-custom-7 ansible_host=10.10.42.2 +# bigboot-test-custom-7 ansible_host=10.10.42.2 # bigboot-test-custom-8 ansible_host=10.10.42.216 # bigboot-test-custom-9 ansible_host=10.1.1.80 [bigboot:vars] -# ansible_user=root -ansible_user=testuser1 +ansible_user=root +# ansible_user=testuser1 # [mailcow_dev] diff --git a/tasks/check_if_shrunk.yml b/tasks/check_if_shrunk.yml new file mode 100644 index 0000000..666bf40 --- /dev/null +++ b/tasks/check_if_shrunk.yml @@ -0,0 +1,21 @@ +--- +- name: Debug item + ansible.builtin.debug: + var: item + +- name: Set device for mount + ansible.builtin.set_fact: + size_three: "{{ ansible_facts['mounts'] | selectattr('device', 'equalto', item['device']) | first }}" + +- name: Debug size_three + ansible.builtin.debug: + var: size_three['size_total'] + +- name: Assert that the filesystem has shrunk + ansible.builtin.assert: + # yamllint disable-line rule:line-length + that: (size_three['size_total'] | int) <= (item['size'] | ansible.builtin.human_to_bytes) + fail_msg: > + Logical Volume {{ item['device'] }} was NOT shrunk as requested. + success_msg: > + Logical Volume {{ item['device'] }} has been shrunk as requested.