From 5cb1b9d68f29938d95a92117ad09971a05dc3eda Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 4 Jun 2025 22:50:46 -0400 Subject: [PATCH] Add tasks to capture block size instead of filesystem size --- tasks/capture_lv_device_details.yml | 16 +++++++++++++--- tasks/check_space_fallback.yml | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tasks/capture_lv_device_details.yml b/tasks/capture_lv_device_details.yml index 9ddf0b2..3e4018c 100644 --- a/tasks/capture_lv_device_details.yml +++ b/tasks/capture_lv_device_details.yml @@ -47,8 +47,17 @@ # that: bigboot_lv_info.size_available > bigboot_expansion_diff | int # fail_msg: There is not enough space available for LV shrinking. -- name: Set initial target size for fallback +- name: Capture UUID for target volume ansible.builtin.set_fact: + bigboot_lv_uuid: "{{ ansible_facts['mounts'] | selectattr('device', 'equalto', bigboot_adjacent_lvm_device) | map(attribute='uuid') | first }}" + +- name: Capture block device information for target logical volume + ansible.builtin.set_fact: + bigboot_lv_dm: "{{ ansible_device_links['uuids'] | dict2items | selectattr('value', 'contains', bigboot_lv_uuid) | map(attribute='key') | first }}" + +- name: Set initial sizes for logical volume and fallback size target + ansible.builtin.set_fact: + bigboot_lv_partsize: "{{ ansible_devices[bigboot_lv_dm]['sectors'] | int * ansible_devices[bigboot_lv_dm]['sectorsize'] | int }}" bigboot_size_target_fallback: "{{ bigboot_size_target | human_to_bytes }}" - name: Check available space and fallback to lower /boot size if required @@ -56,12 +65,13 @@ - name: Capture shrink and fallback sizes ansible.builtin.set_fact: - bigboot_lv_shrink_size: "{{ bigboot_lv_info['size_total'] - bigboot_expansion_diff | int }}" + # we need to get the BLOCK size total, not the filesystem + bigboot_lv_shrink_size: "{{ bigboot_lv_partsize | int - bigboot_expansion_diff | int }}" bigboot_size_target_fallback: "{{ bigboot_size_target_fallback | int | human_readable(unit='G') | regex_replace('\\sGB', 'G') }}" - name: Debug bigboot_lv_shrink_size and bigboot_size_target_fallback ansible.builtin.debug: - msg: "{{ bigboot_lv_shrink_size | int | human_readable(unit='G') }} <-> {{ bigboot_size_target_fallback }} | {{ bigboot_expansion_diff }}" + msg: "{{ bigboot_lv_shrink_size | int | human_readable(unit='G') }} ({{ bigboot_lv_shrink_size }}) <-> {{ bigboot_size_target_fallback }} | {{ bigboot_expansion_diff }}" # - name: Kill the play # ansible.builtin.meta: end_host diff --git a/tasks/check_space_fallback.yml b/tasks/check_space_fallback.yml index 3f92586..f1b0ab7 100644 --- a/tasks/check_space_fallback.yml +++ b/tasks/check_space_fallback.yml @@ -19,7 +19,7 @@ - name: Assert that there will be enough space left over on the target LV ansible.builtin.assert: that: (bigboot_lv_info['size_available'] - bigboot_expansion_diff | int) >= bigboot_lv_size_min | human_to_bytes - success_msg: "There will be enough space left over with a boot size of {{ bigboot_size_target_fallback | int | human_readable(unit='G') }}. ({{ (bigboot_lv_info['size_available'] - bigboot_expansion_diff | int) | human_readable(unit='B') }})" + success_msg: "There will be enough space left over with a boot size of {{ bigboot_size_target_fallback | int | human_readable(unit='G') }}. ({{ (bigboot_lv_info['size_total'] - bigboot_expansion_diff | int) | human_readable(unit='B') }})" fail_msg: "There will NOT be enough space left over with a boot size of {{ bigboot_size_target_fallback | int | human_readable(unit='G') }}." rescue: