From 0606ff81b2d759fb56b8094f1d83d6b76912b0ba Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 8 Jan 2025 12:38:23 -0500 Subject: [PATCH] Finalize development of shrink_lv fix; Testing --- .../roles/shrink_lv/tasks/check_if_shrunk.yml | 13 +++++++++ .../roles/shrink_lv/tasks/main.yaml | 28 ++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/check_if_shrunk.yml diff --git a/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/check_if_shrunk.yml b/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/check_if_shrunk.yml new file mode 100644 index 0000000..8d2086f --- /dev/null +++ b/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/check_if_shrunk.yml @@ -0,0 +1,13 @@ +--- +- name: Set device for mount + ansible.builtin.set_fact: + shrink_lv_set_device: "{{ ansible_facts['mounts'] | selectattr('device', 'equalto', item['device']) | first }}" + +- name: Assert that the filesystem has shrunk + ansible.builtin.assert: + # yamllint disable-line rule:line-length + that: (shrink_lv_set_device['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. diff --git a/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/main.yaml b/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/main.yaml index 1b5dada..f4cac53 100644 --- a/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/main.yaml +++ b/collections/ansible_collections/infra/lvm_snapshots/roles/shrink_lv/tasks/main.yaml @@ -2,10 +2,10 @@ - name: Make sure the required facts are available ansible.builtin.setup: gather_subset: - - "!all" - - "!min" - - kernel - - mounts + - "!all" + - "!min" + - kernel + - mounts - name: Run preflight checks ansible.builtin.include_tasks: preflight.yaml @@ -16,8 +16,8 @@ dest: /usr/lib/dracut/modules.d/99shrink_lv/ mode: "0554" loop: - - module-setup.sh - - shrink.sh + - module-setup.sh + - shrink.sh - name: Resolve and copy the shrink-start script ansible.builtin.template: @@ -39,16 +39,10 @@ - name: Retrieve mount points ansible.builtin.setup: gather_subset: - - "!all" - - "!min" - - mounts + - "!all" + - "!min" + - mounts -- name: Assert that the filesystem has shrunk - ansible.builtin.assert: - # yamllint disable-line rule:line-length - that: (ansible_facts.mounts | selectattr('device', 'equalto', item.device) | map(attribute='size_total') | join | int) <= (item.size | ansible.builtin.human_to_bytes) - fail_msg: > - Logical Volume {{ item.device }} was not shrunk to {{ item.size }} as requested - success_msg: > - Logical Volume {{ item.device }} has been shrunk to {{ item.size }} as requested. +- name: Check if device has shrunken successfully + ansible.builtin.include_tasks: check_if_shrunk.yml loop: "{{ shrink_lv_devices }}"