From a3d5c17253d1da2bee5ab026fe0d0b358c2674ab Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Thu, 5 Jun 2025 02:51:07 -0400 Subject: [PATCH] Add functions to filter plugin; Tweaks --- filter_plugins/get_block_size.py | 14 +++++++++++++- tasks/capture_lv_device_details.yml | 4 ++-- tasks/check_space_fallback.yml | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/filter_plugins/get_block_size.py b/filter_plugins/get_block_size.py index 6247da3..d126466 100755 --- a/filter_plugins/get_block_size.py +++ b/filter_plugins/get_block_size.py @@ -7,7 +7,9 @@ class FilterModule (object): return { 'get_block_size_up': self.get_block_size_up, 'get_block_size_down': self.get_block_size_down, - 'moo': self.moo, + 'get_block_size_up_bytes': self.get_block_size_up_bytes, + 'get_block_size_down_bytes': self.get_block_size_down_bytes, + 'moo': self.moo } @@ -21,6 +23,16 @@ class FilterModule (object): start_size -= 1 return ('{}{}'.format(start_size, 'M')) + def get_block_size_up_bytes(self, start_size): + while start_size % BLOCK_SIZE != 0: + start_size += 1 + return ('{}'.format(start_size)) + + def get_block_size_down_bytes(self, start_size): + while start_size % BLOCK_SIZE != 0: + start_size -= 1 + return ('{}'.format(start_size)) + def moo(self, a_variable): a_new_variable = (str(a_variable) + '~~~~MOOOOOOOOOOOOOOOOOOOOOOOOO! => ' + '%s' % type(a_variable)) return a_new_variable diff --git a/tasks/capture_lv_device_details.yml b/tasks/capture_lv_device_details.yml index 3e4018c..a0d413b 100644 --- a/tasks/capture_lv_device_details.yml +++ b/tasks/capture_lv_device_details.yml @@ -66,12 +66,12 @@ - name: Capture shrink and fallback sizes ansible.builtin.set_fact: # we need to get the BLOCK size total, not the filesystem - bigboot_lv_shrink_size: "{{ bigboot_lv_partsize | int - bigboot_expansion_diff | int }}" + bigboot_lv_shrink_size: "{{ (bigboot_lv_partsize | int - bigboot_expansion_diff | int) | get_block_size_down_bytes }}" 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_lv_shrink_size }}) <-> {{ bigboot_size_target_fallback }} | {{ bigboot_expansion_diff }}" + msg: "{{ bigboot_lv_shrink_size | int | human_readable(unit='G') }} ({{ bigboot_lv_shrink_size | int | human_readable(unit='M') | regex_replace('\\.\\d+\\s+MB') | int | get_block_size_down }}) <-> {{ 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 f1b0ab7..d61ca25 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_total'] - 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: