add op code
This commit is contained in:
parent
4c2eb715fd
commit
659f8c4923
49
bigboot-op.yml
Normal file
49
bigboot-op.yml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
- name: Resize the /boot parition to the desired size
|
||||||
|
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: Shrink a logical volume for /boot expansion if needed
|
||||||
|
ansible.builtin.import_tasks: tasks/bigboot_manage_lv-op.yml
|
||||||
|
|
||||||
|
|
||||||
|
- name: Import hi playbook
|
||||||
|
ansible.builtin.import_playbook: rhc.rear.hi
|
||||||
|
|
||||||
|
|
||||||
|
- name: Expand the /boot partition
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
gather_facts: true
|
||||||
|
strategy: free
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Do we have bigboot_size
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "bigboot_size == {{ bigboot_size }}"
|
||||||
|
|
||||||
|
- name: Do we have bigboot_adjacent_lvm_device
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "bigboot_adjacent_lvm_device == {{ bigboot_adjacent_lvm_device }}"
|
||||||
|
|
||||||
|
- 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 }}"
|
||||||
|
when: bigboot_execute_shrink_lv | bool
|
||||||
|
|
||||||
|
- name: Expand the /boot partition as requested
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: infra.lvm_snapshots.bigboot
|
76
tasks/bigboot_manage_lv-op.yml
Normal file
76
tasks/bigboot_manage_lv-op.yml
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
---
|
||||||
|
- 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
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user