Sync with Develop (#7)

Reviewed-on: #7
Co-authored-by: Chris Hammer <chris@thezengarden.net>
Co-committed-by: Chris Hammer <chris@thezengarden.net>
This commit is contained in:
2025-01-08 16:44:31 -05:00
committed by Chris Hammer
parent 4d10a958d2
commit 4bea43d589
86 changed files with 3588 additions and 194 deletions

View File

@ -73,6 +73,10 @@
changed_when: false
register: bigboot_lv_vg_free_pe
- name: Capture the PV device
ansible.builtin.set_fact:
bigboot_pv: "{{ bigboot_boot_mount['device'][:-1] }}{{ bigboot_boot_mount['device'][-1:] | int + 1 }}"
- name: Format logical volume free PE
ansible.builtin.set_fact:
# Ex:
@ -87,7 +91,7 @@
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
- name: Verify available PE for the volume group
block:
- name: Set flag for Shrink_LV execution
ansible.builtin.set_fact:

56
tasks/check_services.yml Normal file
View File

@ -0,0 +1,56 @@
---
- name: Ensure service facts are available
ansible.builtin.service_facts:
# - name: Capture a list of running services
# ansible.builtin.set_fact:
# bigboot_systemd_running_services:
# "{{ bigboot_systemd_running_services | default([]) + [item['key']] }}"
# loop: "{{ ansible_facts['services'] | dict2items }}"
# loop_control:
# label: "{{ item['key'] }}"
# when:
# - "'running' in item['value']['state']"
# - name: Get the stop timeout value for running services
# ansible.builtin.shell:
# cmd: |
# set -o pipefail
# systemctl show {{ item }} | grep TimeoutStopUSec
# changed_when: false
# register: bigboot_systemd_service_timeout
# loop: "{{ bigboot_systemd_running_services }}"
# - name: Adding services exceeding the timeout threshold to the list of services to disable
# ansible.builtin.set_fact:
# bigboot_services_disabled: "{{ bigboot_services_disabled | default([]) + [item['item']] }}"
# loop: "{{ bigboot_systemd_service_timeout['results'] }}"
# loop_control:
# label: "{{ item['item'] }}"
# when:
# - item['item'] not in bigboot_protected_services
# - item['stdout'] | regex_replace('^.*=(.*$)', '\\1') | community.general.to_minutes >= bigboot_service_max_timeout | int
- name: Adding incompatible services to the list of services to disable
ansible.builtin.set_fact:
bigboot_services_disabled: "{{ bigboot_services_disabled | default([]) + [item] }}"
loop: "{{ bigboot_incompatible_services }}"
when:
- ansible_facts['services'][item] is defined
- ansible_facts['services'][item]['state'] == "running"
- name: Log and disable services
when:
- bigboot_services_disabled is defined
- bigboot_services_disabled | length > 0
block:
- name: Disable services and log their state
ansible.builtin.include_tasks: tasks/disable_systemd_services.yml
loop: "{{ bigboot_services_disabled }}"
- name: Services disabled notice
ansible.builtin.debug:
msg: >-
The following services were disabled, and will be re-enabled post
Bigboot execution: {{ bigboot_services_disabled | join(', ') }}

View File

@ -1,40 +0,0 @@
---
- name: Get the list of services on the host
ansible.builtin.service_facts:
- name: Capture a list of running services
ansible.builtin.set_fact:
bigboot_systemd_running_services:
"{{ bigboot_systemd_running_services | default([]) + [item['key']] }}"
loop: "{{ ansible_facts['services'] | dict2items }}"
loop_control:
label: "{{ item['key'] }}"
when:
- "'running' in item['value']['state']"
- name: Get the stop timeout value for running services
ansible.builtin.shell:
cmd: |
set -o pipefail
systemctl show {{ item }} | grep TimeoutStopUSec
changed_when: false
register: bigboot_systemd_service_timeout
loop: "{{ bigboot_systemd_running_services }}"
- name: Disabling services exceeding the timeout threshold
ansible.builtin.include_tasks: tasks/disable_systemd_services.yml
loop: "{{ bigboot_systemd_service_timeout['results'] }}"
loop_control:
label: "{{ item['item'] }}"
when:
- item['item'] not in bigboot_protected_services
- item['stdout'] | regex_replace('^.*=(.*$)', '\\1') | community.general.to_minutes >= bigboot_service_max_timeout | int
- name: Services disabled notice
ansible.builtin.debug:
msg: >-
The following services were disabled, and will be re-enabled post
Bigboot execution: {{ bigboot_systemd_disabled_services | join(',') }}
when:
- bigboot_systemd_disabled_services is defined
- bigboot_systemd_disabled_services | length > 0

View File

@ -29,16 +29,22 @@
path: "/boot/initramfs-{{ initramfs_kernel_version }}.img.{{ initramfs_backup_extension }}"
state: absent
- name: Check if disable services log exists
ansible.builtin.stat:
path: "{{ bigboot_disabled_services_log }}"
register: bigboot_disabled_services_log_stat
- name: Disable Grub filesystem check
ansible.builtin.import_role:
name: autofsck
tasks_from: cleanup.yml
- name: Remove disabled services log if present
ansible.builtin.file:
path: "{{ bigboot_disabled_services_log }}"
state: absent
when:
- bigboot_disabled_services_log_stat['stat']['exists'] | bool
- name: Flush handlers to remove Grub parameters for fsck
ansible.builtin.meta: flush_handlers
# - name: Check for Bigboot state log and restore services to pre-Bigboot state
# ansible.builtin.import_tasks: tasks/restore_services.yml
# - name: Cleanup previous Bigboot state log if present
# ansible.builtin.file:
# path: "{{ bigboot_disabled_services_log }}"
# state: absent
# when:
# - bigboot_disabled_services_log_stat['stat']['exists'] | bool
...

View File

@ -1,25 +0,0 @@
---
- name: Ensure service facts are available
ansible.builtin.service_facts:
- name: Set Docker state
when:
- ansible_facts['services'][bigboot_docker_service] is defined
block:
- name: Set Docker running state
ansible.builtin.set_fact:
bigboot_docker_running: started
when:
- ansible_facts['services'][bigboot_docker_service]['state'] == "running"
- name: Set Docker enabled state
ansible.builtin.set_fact:
bigboot_docker_enabled: true
when:
- ansible_facts['services'][bigboot_docker_service]['status'] == "enabled"
- name: Ensure Docker service is stopped and disabled
ansible.builtin.service:
name: "{{ bigboot_docker_service }}"
state: stopped
enabled: false

View File

@ -1,25 +0,0 @@
---
- name: Ensure service facts are available
ansible.builtin.service_facts:
- name: Set named-chroot state
when:
- ansible_facts['services'][bigboot_named_chroot_service] is defined
block:
- name: Set named-chroot running state
ansible.builtin.set_fact:
bigboot_named_chroot_running: started
when:
- ansible_facts['services'][bigboot_named_chroot_service]['state'] == "running"
- name: Set named-chroot enabled state
ansible.builtin.set_fact:
bigboot_named_chroot_enabled: true
when:
- ansible_facts['services'][bigboot_named_chroot_service]['status'] == "enabled"
- name: Ensure named-chroot service is stopped and disabled
ansible.builtin.service:
name: "{{ bigboot_named_chroot_service }}"
state: stopped
enabled: false

View File

@ -1,19 +1,21 @@
---
- name: Disabling service for exceeding the timeout threshold
- name: "Save service state: {{ item }}"
ansible.builtin.set_fact:
bigboot_service_to_disable:
service: "{{ ansible_facts['services'][item]['name'] }}"
state: "{{ (ansible_facts['services'][item]['state'] == 'running') | ternary('started', 'stopped') }}"
status: "{{ (ansible_facts['services'][item]['status'] == 'enabled') | ternary('true', 'false') }}"
- name: "Disable and stop service: {{ item }}"
ansible.builtin.service:
name: "{{ item['item'] }}"
name: "{{ item }}"
state: stopped
enabled: false
- name: Append service to list of disabled services
ansible.builtin.set_fact:
bigboot_systemd_disabled_services:
"{{ bigboot_systemd_disabled_services | default([]) + [item['item']] }}"
- name: Log disabled service to log file
- name: "Log disabled service state: {{ item }}"
ansible.builtin.lineinfile:
path: "{{ bigboot_disabled_services_log }}"
line: "{{ item['item'] }}"
line: "{{ item }},{{ bigboot_service_to_disable['state'] }},{{ bigboot_service_to_disable['status'] }}"
create: true
state: present
owner: root

View File

@ -11,15 +11,19 @@
# - name: Reboot to run filesystem checks
# ansible.builtin.reboot:
- name: Reboot to run filesystem checks
ansible.builtin.command: /sbin/shutdown -r +1
# - name: Reboot to run filesystem checks
# ansible.builtin.command: /sbin/shutdown -r +1
- name: Wait for the reboot to complete
ansible.builtin.wait_for_connection:
connect_timeout: 20
sleep: 10
delay: "{{ bigboot_post_reboot_delay | default('70') }}"
timeout: "{{ bigboot_reboot_timeout | default('1800') }}"
# - name: Wait for the reboot to complete
# ansible.builtin.wait_for_connection:
# connect_timeout: 20
# sleep: 10
# delay: "{{ bigboot_post_reboot_delay | default('70') }}"
# timeout: "{{ bigboot_reboot_timeout | default('1800') }}"
- name: Reboot host to run filesystem checks
ansible.builtin.import_role:
name: verified_reboot
- name: Disable Grub filesystem check
ansible.builtin.import_role:

29
tasks/pre-checks.yml Normal file
View File

@ -0,0 +1,29 @@
---
- name: Get /boot mount information
ansible.builtin.set_fact:
bigboot_boot_mount: "{{ ansible_facts.mounts \
| selectattr('mount', 'equalto', '/boot') | first }}"
- name: Set next partition after /boot
ansible.builtin.set_fact:
bigboot_next_device: "{{ bigboot_boot_mount['device'][:-1] }}{{ bigboot_boot_mount['device'][-1:] | int + 1 }}"
- name: Capture partition information from fdisk
ansible.builtin.shell:
cmd: |
set -o pipefail
fdisk -l {{ bigboot_boot_mount['device'][:-1] }} | grep '{{ bigboot_next_device }}'
executable: /bin/bash
changed_when: false
failed_when: bigboot_fdisk_partition['rc'] not in [0, 141]
register: bigboot_fdisk_partition
- name: Debug bigboot_fdisk_partition
ansible.builtin.debug:
var: bigboot_fdisk_partition
- name: Assert that the partition following /boot is of type LVM
ansible.builtin.assert:
that: "'Linux LVM' in bigboot_fdisk_partition['stdout']"
success_msg: The partition following /boot is an LVM partition
fail_msg: The partition following /boot is NOT an LVM partition. Execution halted.

View File

@ -0,0 +1,25 @@
---
- name: Check for Bigboot service state log presence
ansible.builtin.stat:
path: "{{ bigboot_disabled_services_log }}"
register: bigboot_disabled_services_log_stat
- name: Read state log and restore service state
when:
- bigboot_disabled_services_log_stat['stat']['exists'] | bool
block:
- name: Read service state from log
community.general.read_csv:
path: "{{ bigboot_disabled_services_log }}"
fieldnames: service,state,enabled
delimiter: ','
register: bigboot_service_state_contents
- name: Restore service state
ansible.builtin.service:
name: "{{ item['service'] }}"
state: "{{ item['state'] }}"
enabled: "{{ item['enabled'] | bool }}"
loop: "{{ bigboot_service_state_contents['list'] }}"
loop_control:
label: "{{ item['service'] }}"