Skip to content

Commit

Permalink
Bigboot - prepend variable names with role name
Browse files Browse the repository at this point in the history
Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed Dec 14, 2023
1 parent ddb7367 commit 37606ed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/bigboot-internal-variable-names.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- bigboot - Rename internal variables with role name prefix
16 changes: 8 additions & 8 deletions roles/bigboot/tasks/get_boot_device_info.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
- name: Find the boot mount entry
ansible.builtin.set_fact:
_boot_mount_entry: "{{ ansible_facts.mounts | selectattr('mount', 'equalto', '/boot') | first }}"
bigboot_boot_mount_entry: "{{ ansible_facts.mounts | selectattr('mount', 'equalto', '/boot') | first }}"

- name: Calculate the partition to look for
ansible.builtin.set_fact:
_boot_partition_name: "{{ (_boot_mount_entry.device | split('/'))[-1] }}"
bigboot_boot_partition_name: "{{ (bigboot_boot_mount_entry.device | split('/'))[-1] }}"

- name: Find the boot device parent
ansible.builtin.set_fact:
_boot_disk: "{{ item.key }}"
bigboot_boot_disk: "{{ item.key }}"
with_dict: "{{ ansible_facts.devices }}"
when: _boot_partition_name in item.value.partitions
when: bigboot_boot_partition_name in item.value.partitions

- name: Capture boot device details
ansible.builtin.set_fact:
boot_device_partition_prefix: "{{ _boot_partition_name[(_boot_disk | length) : -1] }}"
boot_partition_number: "{{ _boot_partition_name[-1] }}"
boot_device_name: "/dev/{{ _boot_disk }}"
boot_device_original_size: "{{ _boot_mount_entry.size_total | int }}"
bigboot_boot_device_partition_prefix: "{{ bigboot_boot_partition_name[(bigboot_boot_disk | length) : -1] }}"
bigboot_boot_partition_number: "{{ bigboot_boot_partition_name[-1] }}"
bigboot_boot_device_name: "/dev/{{ bigboot_boot_disk }}"
bigboot_boot_device_original_size: "{{ bigboot_boot_mount_entry.size_total | int }}"
10 changes: 3 additions & 7 deletions roles/bigboot/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@

- name: Capture boot device new size
ansible.builtin.set_fact:
boot_device_new_size: "{{ (ansible_facts.mounts | selectattr('mount', 'equalto', '/boot') | first).size_total | int }}"

- name: Capture expected device size
ansible.builtin.set_fact:
expected_size: "{{ (bigboot_size | human_to_bytes | int) + (boot_device_original_size | int) }}"
bigboot_boot_device_new_size: "{{ (ansible_facts.mounts | selectattr('mount', 'equalto', '/boot') | first).size_total | int }}"

- name: Validate boot partition new size
ansible.builtin.assert:
that:
- boot_device_new_size != boot_device_original_size
fail_msg: "Boot partition size '{{ boot_device_new_size }}' did not change"
- bigboot_boot_device_new_size != bigboot_boot_device_original_size
fail_msg: "Boot partition size '{{ bigboot_boot_device_new_size }}' did not change"
4 changes: 2 additions & 2 deletions roles/bigboot/templates/increase-boot-partition.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ main() {
start=$(/usr/bin/date +%s)
disable_lvm_lock
# run bigboot.sh to increase boot partition and file system size
ret=$(sh /usr/bin/bigboot.sh -d="{{ boot_device_name }}" -s="{{ bigboot_size }}" -b="{{ boot_partition_number }}" -p="{{ boot_device_partition_prefix }}" 2>/dev/kmsg)
ret=$(sh /usr/bin/bigboot.sh -d="{{ bigboot_boot_device_name }}" -s="{{ bigboot_size }}" -b="{{ bigboot_boot_partition_number }}" -p="{{ bigboot_boot_device_partition_prefix }}" 2>/dev/kmsg)
status=$?
end=$(/usr/bin/date +%s)
# write the log file
if [[ $status -eq 0 ]]; then
echo "[$name] Boot partition {{ boot_device_name }} successfully increased by {{ bigboot_size }} ("$((end-start))" seconds) " >/dev/kmsg
echo "[$name] Boot partition {{ bigboot_boot_device_name }} successfully increased by {{ bigboot_size }} ("$((end-start))" seconds) " >/dev/kmsg
else
echo "[$name] Failed to extend boot partition: $ret ("$((end-start))" seconds)" >/dev/kmsg
fi
Expand Down

0 comments on commit 37606ed

Please sign in to comment.