add bigboot-v3.yml, supporting filter_plugins, and fuzzy logic
All checks were successful
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-centos9) (push) Successful in 18s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian11) (push) Successful in 15s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian12) (push) Successful in 15s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-fedora39) (push) Successful in 16s

This commit is contained in:
2024-02-15 21:06:58 -05:00
parent 9570563b72
commit e50d15a72c
8 changed files with 176 additions and 2 deletions

View File

@ -0,0 +1,83 @@
---
- name: Capture logical volume adjacent to /boot
ansible.builtin.shell:
cmd: |
set -o pipefail
lsblk -p -o name,type|grep lvm|head -1
executable: /bin/bash
changed_when: false
register: bigboot_adjacent_lvm
- name: Set adjacent LVM device name
ansible.builtin.set_fact:
bigboot_adjacent_lvm_device: "{{ bigboot_adjacent_lvm.stdout | regex_replace('.*(\\/dev.*)\\s+.*$', '\\1') }}"
- name: Get logical volume mount information
ansible.builtin.set_fact:
bigboot_lv_info: "{{ ansible_facts.mounts \
| selectattr('device', 'equalto', bigboot_adjacent_lvm_device | trim) | first }}"
- name: Capture shrink size for logical volume
ansible.builtin.set_fact:
bigboot_lv_shrink_size: "{{ bigboot_lv_info.size_total - bigboot_expansion_diff | int }}"
- name: Capture logical volume name
ansible.builtin.shell:
cmd: |
set -o pipefail
lvdisplay {{ bigboot_adjacent_lvm_device }} | grep -i 'vg name'
executable: /bin/bash
changed_when: false
register: bigboot_lv_vg_name
- name: Format logical volume name
ansible.builtin.set_fact:
bigboot_lv_vg_name: "{{ bigboot_lv_vg_name.stdout | regex_replace('^.*?\\s+(\\w+)$', '\\1') }}"
- name: Capture volume group free PE
ansible.builtin.shell:
cmd: |
set -o pipefail
vgdisplay {{ bigboot_lv_vg_name }} | grep -i 'free'
executable: /bin/bash
changed_when: false
register: bigboot_lv_vg_free_pe
- name: Format logical volume free PE
ansible.builtin.set_fact:
# Ex:
# Free PE / Size 320 / 1.25 GiB"
# Free PE / Size 189 / 756.00 MiB"
# 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
ansible.builtin.set_fact:
bigboot_lv_size_in_mb:
"{{ bigboot_lv_vg_free_pe | regex_replace('i|\\s+|<', '') | human_to_bytes | human_readable(unit='M') }}"
# "{{ bigboot_lv_vg_free_pe | regex_replace('i', '') | regex_replace(' ', '') | human_to_bytes | human_readable(unit='M') }}"
bigboot_size_in_mb: "{{ bigboot_size[:-1] }}"
- name: Check if we can shrink the logical volume
block:
- name: Assert if we need to execute the shrink_lv role
ansible.builtin.assert:
that:
- bigboot_lv_vg_free_pe[:-4] != ''
- (bigboot_lv_size_in_mb[:-6] | int - bigboot_size_in_mb | int ) >= 0
# - (bigboot_lv_info.size_available - bigboot_size | human_to_bytes) >= 0
fail_msg: Not enough free PE available for /boot expansion.
rescue:
- name: Assert there is free space available for shrinking
ansible.builtin.assert:
that: (bigboot_lv_info.size_available - bigboot_size | 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 | human_readable | regex_replace('^(.*\\.\\d+)\\s+(\\w).*$', '\\1\\2') }}"

View File

@ -0,0 +1,36 @@
---
- name: Get /boot mount information
ansible.builtin.set_fact:
bigboot_boot_info: "{{ ansible_facts.mounts \
| selectattr('mount', 'equalto', '/boot') | first }}"
- name: Capture required expansion space
ansible.builtin.set_fact:
bigboot_expansion_diff:
"{{ bigboot_size | human_to_bytes - bigboot_boot_info.size_total | int }}"
- 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: "{{ bigboot_size_expansion_mb[:-2] \
| regex_replace('\\.\\d+ ', '') \
| int | get_block_size_up }}"
- name: Validate if we need to expand boot
block:
- name: Assert that /boot requires expansion
ansible.builtin.assert:
that: bigboot_expansion_diff | int <= 0
fail_msg: The /boot partition will need to be resized
success_msg: The /boot partition is already at the desired size
- name: The /boot parition is already at the desired size.
ansible.builtin.meta: end_host
rescue:
- name: Expansion of /boot required
ansible.builtin.debug:
msg: "Expanding /boot by an additional {{ bigboot_size }}."