From f6d129a5936a44aa108b1c773c2c7fca6a268702 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Tue, 26 Mar 2024 15:50:22 -0400 Subject: [PATCH] cleanup --- .unused_requirements.yml | 17 ------- bigboot-op.yml | 46 ----------------- bigboot-standalone.yml | 16 ------ bigboot.yml | 34 +++++++++++-- preflight.yml | 86 -------------------------------- shrink_lv.yml | 18 ------- tasks/bigboot_manage_lv-noop.yml | 76 ---------------------------- tasks/bigboot_manage_lv-op.yml | 76 ---------------------------- tasks/bigboot_manage_lv.yml | 79 ----------------------------- 9 files changed, 30 insertions(+), 418 deletions(-) delete mode 100644 .unused_requirements.yml delete mode 100644 bigboot-op.yml delete mode 100644 bigboot-standalone.yml delete mode 100644 preflight.yml delete mode 100644 shrink_lv.yml delete mode 100644 tasks/bigboot_manage_lv-noop.yml delete mode 100644 tasks/bigboot_manage_lv-op.yml delete mode 100644 tasks/bigboot_manage_lv.yml diff --git a/.unused_requirements.yml b/.unused_requirements.yml deleted file mode 100644 index d7e423b..0000000 --- a/.unused_requirements.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -roles: [] - -collections: - # RedHat COP - infra.lvm_snapshots - - name: infra.lvm_snapshots - source: https://github.com/redhat-cop/infra.lvm_snapshots.git - type: git - version: main - - - # Galaxy Collections - - name: community.general - - name: ansible.posix - - -... diff --git a/bigboot-op.yml b/bigboot-op.yml deleted file mode 100644 index 5b6f12d..0000000 --- a/bigboot-op.yml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- name: Capture boot and logical volume information - hosts: all - become: true - gather_facts: true - strategy: free - - vars: - bigboot_size_target: 1G - - - tasks: - - name: Capture boot device details - ansible.builtin.import_tasks: tasks/capture_boot_device_details.yml - - - name: Capture logical volume information - ansible.builtin.import_tasks: tasks/capture_lv_device_details.yml - - -- name: Perform a ReaR backup if any disk modifications are to be made - ansible.builtin.import_playbook: rhc.rear.rear_backup - when: - - bigboot_execute_bigboot | bool - - -- name: Perform logical volume and boot parition resizing as needed - hosts: all - become: true - gather_facts: true - strategy: free - - tasks: - - name: Expand the logical volume to support /boot expansion - 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 }}" - when: - - bigboot_execute_shrink_lv | bool - - - name: Expand the /boot partition as requested - ansible.builtin.import_role: - name: infra.lvm_snapshots.bigboot - when: bigboot_execute_bigboot | bool diff --git a/bigboot-standalone.yml b/bigboot-standalone.yml deleted file mode 100644 index 5a82639..0000000 --- a/bigboot-standalone.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: Resize the /boot parition to the desired size - hosts: all - become: true - gather_facts: true - - - vars: - bigboot_size: "{{ bigboot_new_size | default('') }}" - - - roles: - - infra.lvm_snapshots.bigboot - - -... diff --git a/bigboot.yml b/bigboot.yml index 3932045..5b6f12d 100644 --- a/bigboot.yml +++ b/bigboot.yml @@ -1,5 +1,5 @@ --- -- name: Resize the /boot parition to the desired size +- name: Capture boot and logical volume information hosts: all become: true gather_facts: true @@ -8,13 +8,39 @@ vars: bigboot_size_target: 1G + tasks: - name: Capture boot device details ansible.builtin.import_tasks: tasks/capture_boot_device_details.yml - - name: Shrink a logical volume for /boot expansion if needed - ansible.builtin.import_tasks: tasks/bigboot_manage_lv.yml + - name: Capture logical volume information + ansible.builtin.import_tasks: tasks/capture_lv_device_details.yml + + +- name: Perform a ReaR backup if any disk modifications are to be made + ansible.builtin.import_playbook: rhc.rear.rear_backup + when: + - bigboot_execute_bigboot | bool + + +- name: Perform logical volume and boot parition resizing as needed + hosts: all + become: true + gather_facts: true + strategy: free + + tasks: + - name: Expand the logical volume to support /boot expansion + 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 }}" + when: + - bigboot_execute_shrink_lv | bool - name: Expand the /boot partition as requested - ansible.builtin.include_role: + ansible.builtin.import_role: name: infra.lvm_snapshots.bigboot + when: bigboot_execute_bigboot | bool diff --git a/preflight.yml b/preflight.yml deleted file mode 100644 index fdab49a..0000000 --- a/preflight.yml +++ /dev/null @@ -1,86 +0,0 @@ ---- -- name: Create VG and LVOL for shrink_lv testing - hosts: all - become: true - gather_facts: true - - - vars: - __part_size: 80GB - __partition_devices: - # - /dev/sdb - # - /dev/sdc - - /dev/sdd - - /dev/sde - - __vg_name : test-vg02 - __lv_name : test-lv02 - __lv_size : 120g - __lv_mount : "/lvol/{{ __lv_name }}" - __lv_fstype : ext4 - - - tasks: - - name: Debug __partition_devices - ansible.builtin.debug: - msg: - - "{{ __partition_devices }}" - - "{{ __partition_devices | join(',') }}" - - "{{ __partition_devices | \ - map('regex_replace', '(?Psd.*)', '\\g' + '1', multiline=True) }}" - verbosity: 1 - - - - name: Install LVM2 - ansible.builtin.package: - name : lvm2 - state : present - - - - name: Create partitions on all drives - community.general.parted: - device : "{{ item }}" - number : 1 - flags : ['lvm'] - state : present - part_end : "{{ __part_size }}" - loop: "{{ __partition_devices }}" - - - - name: Create VG - community.general.lvg: - vg : "{{ __vg_name }}" - pvs : "{{ __partition_devices | \ - map('regex_replace', '(?Psd.*)', '\\g' + '1', multiline=True) }}" - - - - name: Create LV - community.general.lvol: - vg : "{{ __vg_name }}" - lv : "{{ __lv_name }}" - size : "{{ __lv_size }}" - force : true - - - - name: Create lvol mount point - ansible.builtin.file: - path : "{{ __lv_mount }}" - state : directory - mode : "0755" - - - - name: Create filesystem on {{ __lv_name }} - community.general.filesystem: - dev : "/dev/{{ __vg_name }}/{{ __lv_name }}" - fstype : "{{ __lv_fstype }}" - - - - name: Mount {{ __lv_mount }} - ansible.posix.mount: - path : "{{ __lv_mount }}" - src : "/dev/{{ __vg_name }}/{{ __lv_name }}" - fstype : "{{ __lv_fstype }}" - state : mounted - - -... diff --git a/shrink_lv.yml b/shrink_lv.yml deleted file mode 100644 index 1ea00a8..0000000 --- a/shrink_lv.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Shrink specific logical volume to given size - hosts: all - become: true - gather_facts: true - - - vars: - shrink_lv_devices: - - device: "{{ shrink_lv_logical_volume | default('') }}" - size: "{{ shrink_lv_volume_size | default('') }}" - - - roles: - - infra.lvm_snapshots.shrink_lv - - -... diff --git a/tasks/bigboot_manage_lv-noop.yml b/tasks/bigboot_manage_lv-noop.yml deleted file mode 100644 index 62ff11d..0000000 --- a/tasks/bigboot_manage_lv-noop.yml +++ /dev/null @@ -1,76 +0,0 @@ ---- -- 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: 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 | 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('VG\\s+Name\\s+(.*)$', '\\1') }}" - -- name: Capture volume group free PE - ansible.builtin.shell: - cmd: | - set -o pipefail - vgdisplay {{ bigboot_lv_vg_name | trim }} | 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 414 / <1.62 GiB - # Free PE / Size 0 / 0 - bigboot_lv_vg_free_pe: "{{ bigboot_lv_vg_free_pe.stdout | regex_replace('^.*/.*/\\s+[<]?(.*)', '\\1') }}" - -- name: Get size in MB for PE and - ansible.builtin.set_fact: - bigboot_lv_pe_size_in_mb: - "{{ bigboot_lv_vg_free_pe | regex_replace('i|\\s+|<', '') | human_to_bytes | human_readable(unit='M') }}" - -- 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 to gain free PE - ansible.builtin.assert: - that: (bigboot_lv_pe_size_in_mb[:-3] | int | round) | int > bigboot_size[:-1] | int - fail_msg: Not enough PE to expand /boot. - - rescue: - - name: Set flag to execute shrink_lv - ansible.builtin.set_fact: - bigboot_execute_shrink_lv: true - diff --git a/tasks/bigboot_manage_lv-op.yml b/tasks/bigboot_manage_lv-op.yml deleted file mode 100644 index 62ff11d..0000000 --- a/tasks/bigboot_manage_lv-op.yml +++ /dev/null @@ -1,76 +0,0 @@ ---- -- 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: 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 | 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('VG\\s+Name\\s+(.*)$', '\\1') }}" - -- name: Capture volume group free PE - ansible.builtin.shell: - cmd: | - set -o pipefail - vgdisplay {{ bigboot_lv_vg_name | trim }} | 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 414 / <1.62 GiB - # Free PE / Size 0 / 0 - bigboot_lv_vg_free_pe: "{{ bigboot_lv_vg_free_pe.stdout | regex_replace('^.*/.*/\\s+[<]?(.*)', '\\1') }}" - -- name: Get size in MB for PE and - ansible.builtin.set_fact: - bigboot_lv_pe_size_in_mb: - "{{ bigboot_lv_vg_free_pe | regex_replace('i|\\s+|<', '') | human_to_bytes | human_readable(unit='M') }}" - -- 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 to gain free PE - ansible.builtin.assert: - that: (bigboot_lv_pe_size_in_mb[:-3] | int | round) | int > bigboot_size[:-1] | int - fail_msg: Not enough PE to expand /boot. - - rescue: - - name: Set flag to execute shrink_lv - ansible.builtin.set_fact: - bigboot_execute_shrink_lv: true - diff --git a/tasks/bigboot_manage_lv.yml b/tasks/bigboot_manage_lv.yml deleted file mode 100644 index 726b53a..0000000 --- a/tasks/bigboot_manage_lv.yml +++ /dev/null @@ -1,79 +0,0 @@ ---- -- 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: 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 | 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('VG\\s+Name\\s+(.*)$', '\\1') }}" - -- name: Capture volume group free PE - ansible.builtin.shell: - cmd: | - set -o pipefail - vgdisplay {{ bigboot_lv_vg_name | trim }} | 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 414 / <1.62 GiB - # Free PE / Size 0 / 0 - bigboot_lv_vg_free_pe: "{{ bigboot_lv_vg_free_pe.stdout | regex_replace('^.*/.*/\\s+[<]?(.*)', '\\1') }}" - -- name: Get size in MB for PE and - ansible.builtin.set_fact: - bigboot_lv_pe_size_in_mb: - "{{ bigboot_lv_vg_free_pe | regex_replace('i|\\s+|<', '') | human_to_bytes | human_readable(unit='M') }}" - -- 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 to gain free PE - ansible.builtin.assert: - that: (bigboot_lv_pe_size_in_mb[:-3] | int | round) | int > bigboot_size[:-1] | int - fail_msg: Not enough PE to expand /boot. - - rescue: - - 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 }}"