Refactor boot and LV code
All checks were successful
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-centos9) (push) Successful in 16s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian11) (push) Successful in 13s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian12) (push) Successful in 13s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-fedora39) (push) Successful in 15s

This commit is contained in:
2024-02-17 22:44:30 -05:00
parent a39826b49b
commit 8eec5d34d4
4 changed files with 18 additions and 74 deletions

View File

@ -17,9 +17,14 @@
bigboot_lv_info: "{{ ansible_facts.mounts \
| selectattr('device', 'equalto', bigboot_adjacent_lvm_device | trim) | first }}"
- name: Assert that there is space on the logical volume for shrinkage
ansible.builtin.assert:
that: bigboot_lv_info.size_available > bigboot_expansion_diff | int
fail_msg: There is not enough space available for LV shrinking.
- name: Capture shrink size for logical volume
ansible.builtin.set_fact:
bigboot_lv_shrink_size: "{{ bigboot_lv_info.size_total - bigboot_expansion_diff | human_to_bytes }}"
bigboot_lv_shrink_size: "{{ bigboot_lv_info.size_total - bigboot_expansion_diff | int }}"
- name: Capture logical volume name
ansible.builtin.shell:
@ -52,31 +57,23 @@
# Free PE / Size 0 / 0
bigboot_lv_vg_free_pe: "{{ bigboot_lv_vg_free_pe.stdout | regex_replace('^.*/.*/\\s+[<]?(.*)', '\\1') }}"
- name: Get size only from the values
- name: Get size in MB for PE and
ansible.builtin.set_fact:
bigboot_lv_size_in_mb:
bigboot_lv_pe_size_in_mb:
"{{ bigboot_lv_vg_free_pe | regex_replace('i|\\s+|<', '') | human_to_bytes | human_readable(unit='M') }}"
bigboot_size_in_mb: "{{ bigboot_size_target[:-1] }}"
- name: Check if we can shrink the logical volume
- name: Verify if there's available PE or not and execute Shrink_LV
block:
- name: Assert if we need to execute the shrink_lv role
- name: Assert if we need to execute the shrink_lv role to gain free PE
ansible.builtin.assert:
that:
- bigboot_lv_vg_free_pe[:-4] != ''
- (bigboot_lv_size_in_mb[:-6] | int - bigboot_size_in_mb | int ) >= 0
fail_msg: Not enough free PE available for /boot expansion.
that: (bigboot_lv_pe_size_in_mb[:-3] | int | round) | int > bigboot_size_target[:-1] | int
fail_msg: Not enough PE to expand /boot.
rescue:
- name: Assert there is free space available for shrinking
ansible.builtin.assert:
that: (bigboot_lv_info.size_available - bigboot_size_target | human_to_bytes) >= 0
fail_msg: "Not enough space available on {{ bigboot_adjacent_lvm_device | trim }} for shrinking."
- name: Execute Shrink_LV role to resize target logical volume
ansible.builtin.import_role:
name: infra.lvm_snapshots.shrink_lv
vars:
shrink_lv_devices:
- device: "{{ bigboot_adjacent_lvm_device | trim }}"
size: "{{ (bigboot_lv_shrink_size | int / bigboot_shrink_padding) | regex_replace('\\..*$', '') }}"
size: "{{ bigboot_lv_shrink_size | int }}"

View File

@ -12,9 +12,9 @@
ansible.builtin.set_fact:
bigboot_boot_partsize: "{{ ansible_devices[bigboot_boot_device[:-1]].partitions[bigboot_boot_device].size }}"
- name: Debug bigboot_boot_partsize
- name: Display current parition size for /boot
ansible.builtin.debug:
var: bigboot_boot_partsize
msg: "/boot ({{ bigboot_boot_mount.device }}): {{ bigboot_boot_partsize }}"
- name: Capture required expansion space
ansible.builtin.set_fact:
@ -22,22 +22,13 @@
"{{ bigboot_size | human_to_bytes - bigboot_boot_partsize | human_to_bytes }}"
no_log: false
- name: Debug bigboot_expansion_diff
ansible.builtin.debug:
var: bigboot_expansion_diff
- name: Boo
ansible.builtin.meta: end_host
- name: Convert size difference to MB
ansible.builtin.set_fact:
bigboot_size_expansion_mb: "{{ bigboot_expansion_diff | int | human_readable(unit='M') }}"
- name: Set bigboot size 4k aligned
ansible.builtin.set_fact:
bigboot_size_target: "{{ bigboot_size_expansion_mb[:-2] \
| regex_replace('\\.\\d+ ', '') \
| int | get_block_size_up }}"
bigboot_size_target: "{{ bigboot_size_expansion_mb[:-2] | int | get_block_size_up }}"
- name: Validate if we need to expand boot
block:
@ -53,4 +44,4 @@
rescue:
- name: Expansion of /boot required
ansible.builtin.debug:
msg: "Expanding /boot by an additional {{ bigboot_size_target }}."
msg: "Will need to expand /boot by an additional {{ bigboot_size_target }}."