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:
Chris Hammer 2024-02-17 22:44:30 -05:00
parent a39826b49b
commit 8eec5d34d4
4 changed files with 18 additions and 74 deletions

View File

@ -7,7 +7,7 @@ gathering = smart
gather_timeout = 600 gather_timeout = 600
fact_caching = jsonfile fact_caching = jsonfile
fact_caching_connection = /tmp/.ansible_facts fact_caching_connection = /tmp/.ansible_facts
fact_caching_timeout = 300 fact_caching_timeout = 10
retry_files_enabled = false retry_files_enabled = false
forks = 40 forks = 40
timeout = 30 timeout = 30

View File

@ -1,44 +0,0 @@
---
- name: Expand /boot partition on target host
hosts: all
become: true
gather_facts: true
tasks:
- name: Expand boot partition
block:
- name: Execute Bigboot role to resize /boot
ansible.builtin.import_role:
name: infra.lvm_snapshots.bigboot
rescue:
- name: Get the target device information and calculate padding
ansible.builtin.set_fact:
bigboot_shrink_target_info: "{{ ansible_facts.mounts \
| selectattr('device', 'equalto', bigboot_shrink_target) | first }}"
bigboot_size_padded: (bigboot_size | human_to_bytes * bigboot_shrink_padding) | int
- name: Calculate the new logical volume size
ansible.builtin.set_fact:
shrink_lv_volume_size: "{{ (bigboot_shrink_target_info.size_total - bigboot_size_padded | int) \
| ansible.builtin.human_readable | ansible.builtin.regex_replace(' ', '') }}"
- name: Show resize information
ansible.builtin.debug:
msg: "Shrinking {{ bigboot_shrink_target }} from \
{{ bigboot_shrink_target_info.size_total | ansible.builtin.human_readable }} to \
{{ shrink_lv_volume_size[:-1] | ansible.builtin.regex_replace('^(\\d+)\\.\\d+(\\w).*', '\\1\\2') }} \
to expand /boot partition by {{ bigboot_size }}."
- 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_shrink_target }}"
size: "{{ shrink_lv_volume_size[:-1] \
| ansible.builtin.regex_replace('^(\\d+)\\.\\d+(\\w).*', '\\1\\2') }}"
- name: Execute Bigboot role to resize /boot
ansible.builtin.import_role:
name: infra.lvm_snapshots.bigboot

View File

@ -17,9 +17,14 @@
bigboot_lv_info: "{{ ansible_facts.mounts \ bigboot_lv_info: "{{ ansible_facts.mounts \
| selectattr('device', 'equalto', bigboot_adjacent_lvm_device | trim) | first }}" | 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 - name: Capture shrink size for logical volume
ansible.builtin.set_fact: 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 - name: Capture logical volume name
ansible.builtin.shell: ansible.builtin.shell:
@ -52,31 +57,23 @@
# Free PE / Size 0 / 0 # Free PE / Size 0 / 0
bigboot_lv_vg_free_pe: "{{ bigboot_lv_vg_free_pe.stdout | regex_replace('^.*/.*/\\s+[<]?(.*)', '\\1') }}" 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: 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_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: 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: ansible.builtin.assert:
that: that: (bigboot_lv_pe_size_in_mb[:-3] | int | round) | int > bigboot_size_target[:-1] | int
- bigboot_lv_vg_free_pe[:-4] != '' fail_msg: Not enough PE to expand /boot.
- (bigboot_lv_size_in_mb[:-6] | int - bigboot_size_in_mb | int ) >= 0
fail_msg: Not enough free PE available for /boot expansion.
rescue: 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 - name: Execute Shrink_LV role to resize target logical volume
ansible.builtin.import_role: ansible.builtin.import_role:
name: infra.lvm_snapshots.shrink_lv name: infra.lvm_snapshots.shrink_lv
vars: vars:
shrink_lv_devices: shrink_lv_devices:
- device: "{{ bigboot_adjacent_lvm_device | trim }}" - 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: ansible.builtin.set_fact:
bigboot_boot_partsize: "{{ ansible_devices[bigboot_boot_device[:-1]].partitions[bigboot_boot_device].size }}" 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: ansible.builtin.debug:
var: bigboot_boot_partsize msg: "/boot ({{ bigboot_boot_mount.device }}): {{ bigboot_boot_partsize }}"
- name: Capture required expansion space - name: Capture required expansion space
ansible.builtin.set_fact: ansible.builtin.set_fact:
@ -22,22 +22,13 @@
"{{ bigboot_size | human_to_bytes - bigboot_boot_partsize | human_to_bytes }}" "{{ bigboot_size | human_to_bytes - bigboot_boot_partsize | human_to_bytes }}"
no_log: false 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 - name: Convert size difference to MB
ansible.builtin.set_fact: ansible.builtin.set_fact:
bigboot_size_expansion_mb: "{{ bigboot_expansion_diff | int | human_readable(unit='M') }}" bigboot_size_expansion_mb: "{{ bigboot_expansion_diff | int | human_readable(unit='M') }}"
- name: Set bigboot size 4k aligned - name: Set bigboot size 4k aligned
ansible.builtin.set_fact: ansible.builtin.set_fact:
bigboot_size_target: "{{ bigboot_size_expansion_mb[:-2] \ bigboot_size_target: "{{ bigboot_size_expansion_mb[:-2] | int | get_block_size_up }}"
| regex_replace('\\.\\d+ ', '') \
| int | get_block_size_up }}"
- name: Validate if we need to expand boot - name: Validate if we need to expand boot
block: block:
@ -53,4 +44,4 @@
rescue: rescue:
- name: Expansion of /boot required - name: Expansion of /boot required
ansible.builtin.debug: ansible.builtin.debug:
msg: "Expanding /boot by an additional {{ bigboot_size_target }}." msg: "Will need to expand /boot by an additional {{ bigboot_size_target }}."