10 Commits
main ... wip

Author SHA1 Message Date
80c1e0a09c Revert changes which are not needed 2024-08-20 14:20:02 -04:00
862908fe0c Sync with develop branch 2024-08-20 14:12:31 -04:00
035fc1b57c Add initial pre-checks 2024-08-19 17:53:08 -04:00
9f9a798d91 more task rename; block remove 2024-08-07 10:57:30 -04:00
677ba57401 more task rename 2024-08-07 10:54:20 -04:00
2a8ce9fa89 task rename 2024-08-07 10:51:40 -04:00
684c1bef51 cleanup and add code block 2024-08-07 10:17:05 -04:00
e7e90aaaf5 cleanup 2024-08-06 11:47:21 -04:00
aba39cbad4 new service state handling 2024-08-06 11:30:30 -04:00
fa7f4d0e31 sync with upstream; re-work in progress 2024-07-16 15:19:12 -04:00
14 changed files with 154 additions and 165 deletions

View File

@ -9,16 +9,10 @@
- bigboot_vars.yml
tasks:
- name: Perform service and filesystem checks prior to Bigboot execution
- name: Perform filesystem check prior to Bigboot execution
ansible.builtin.import_tasks: tasks/grub_filesystem_check.yml
when:
- bigboot_data[inventory_hostname]['bigboot_execute_bigboot'] | default(false) | bool
block:
- name: Check for and disable services exceeding the timeout threshold
ansible.builtin.import_tasks: tasks/check_systemd_services.yml
- name: Perform filesystem check prior to Bigboot execution
ansible.builtin.import_tasks: tasks/grub_filesystem_check.yml
- name: Extend the timeout values for physical hosts
ansible.builtin.set_fact:
@ -45,31 +39,5 @@
when:
- bigboot_data[inventory_hostname]['bigboot_execute_bigboot'] | bool
- name: Ensure service facts are available
ansible.builtin.service_facts:
- name: Restore named-chroot service to its pre-Bigboot state
ansible.builtin.service:
name: "{{ bigboot_named_chroot_service }}"
state: "{{ bigboot_data[inventory_hostname]['bigboot_named_chroot_running'] }}"
enabled: "{{ bigboot_data[inventory_hostname]['bigboot_named_chroot_enabled'] }}"
when:
- ansible_facts['services'][bigboot_named_chroot_service] is defined
- name: Restore Docker service to its pre-Bigboot state
ansible.builtin.service:
name: "{{ bigboot_docker_service }}"
state: "{{ bigboot_data[inventory_hostname]['bigboot_docker_running'] }}"
enabled: "{{ bigboot_data[inventory_hostname]['bigboot_docker_enabled'] }}"
when:
- ansible_facts['services'][bigboot_docker_service] is defined
- name: Re-enabling services previously disabled
ansible.builtin.service:
name: "{{ item }}"
state: started
enabled: true
loop: "{{ bigboot_systemd_disabled_services }}"
when:
- bigboot_systemd_disabled_services is defined
- bigboot_systemd_disabled_services | length > 0
- name: Restore service state for disabled services
ansible.builtin.import_tasks: tasks/restore_services.yml

View File

@ -12,11 +12,8 @@
- name: Cleanup from any previous executions
ansible.builtin.import_tasks: tasks/cleanup.yml
- name: Stop and disable the Docker service if present and running
ansible.builtin.import_tasks: tasks/disable_docker_service.yml
- name: Stop and disable the named-chroot service if present and running
ansible.builtin.import_tasks: tasks/disable_named_chroot_service.yml
- name: Check for services that require being disabled
ansible.builtin.import_tasks: tasks/check_services.yml
- name: Set boot device details
ansible.builtin.import_tasks: tasks/capture_boot_device_details.yml
@ -24,6 +21,11 @@
- name: Set logical volume information
ansible.builtin.import_tasks: tasks/capture_lv_device_details.yml
- name: Run pre-checks to verify environment
ansible.builtin.import_tasks: tasks/pre-checks.yml
when:
- bigboot_execute_bigboot | bool
- name: Set environment for subsequent workflow nodes
ansible.builtin.set_stats:
aggregate: true
@ -36,10 +38,6 @@
'bigboot_adjacent_lvm_device': bigboot_adjacent_lvm_device,
'bigboot_lv_shrink_size': bigboot_lv_shrink_size | int,
'bigboot_size': bigboot_size,
'bigboot_docker_running': bigboot_docker_running,
'bigboot_docker_enabled': bigboot_docker_enabled,
'bigboot_named_chroot_running': bigboot_named_chroot_running,
'bigboot_named_chroot_enabled': bigboot_named_chroot_enabled,
'ip_addresses': ansible_all_ipv4_addresses,
'server_hostname': ansible_hostname
}

View File

@ -17,6 +17,6 @@ collections:
version: 1.5.4
- name: infra.lvm_snapshots
version: 2.0.2
version: 2.1.0
...

View File

@ -19,7 +19,7 @@
- name: Capture required expansion space
ansible.builtin.set_fact:
bigboot_expansion_diff:
"{{ bigboot_size_target | human_to_bytes - bigboot_boot_partsize | human_to_bytes }}"
"{{ bigboot_partition_size | human_to_bytes - bigboot_boot_partsize | human_to_bytes }}"
- name: Convert size difference to MB
ansible.builtin.set_fact:
@ -27,7 +27,7 @@
- name: Set bigboot size 4k aligned
ansible.builtin.set_fact:
bigboot_size: "{{ bigboot_size_expansion_mb[:-2] | int | get_block_size_up }}"
bigboot_partition_size: "{{ bigboot_size_expansion_mb[:-2] | int | get_block_size_up }}"
- name: Validate if we need to expand boot
block:
@ -48,4 +48,4 @@
- name: Expansion of /boot required
ansible.builtin.debug:
msg: "Will need to expand /boot by an additional {{ bigboot_size }}."
msg: "Will need to expand /boot by an additional {{ bigboot_partition_size }}."

View File

@ -87,7 +87,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,12 +29,10 @@
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: Check for Bigboot state log and restore services to pre-Bigboot state
ansible.builtin.import_tasks: tasks/restore_services.yml
- name: Remove disabled services log if present
- name: Cleanup previous Bigboot state log if present
ansible.builtin.file:
path: "{{ bigboot_disabled_services_log }}"
state: absent

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

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'] }}"

View File

@ -1,26 +1,29 @@
---
ansible_ssh_retries: 10
bigboot_size_target: 1G
bigboot_partition_size: 1G
bigboot_post_reboot_delay: 70
bigboot_reboot_timeout: 1800
bigboot_skip_rear_backup: false
bigboot_docker_service: docker.service
bigboot_docker_running: stopped
bigboot_docker_enabled: false
bigboot_named_chroot_service: named-chroot.service
bigboot_named_chroot_running: stopped
bigboot_named_chroot_enabled: false
# Max value in minutes for the timeout threshold:
# Max value in minutes for services timeout threshold:
bigboot_service_max_timeout: 5
# List of services incompatible with calculations
# to obtain required disk information:
#
# (These services will ALWAYS be disabled)
bigboot_incompatible_services:
- docker.service
- named-chroot.service
# List of services which will be excluded from being
# disabled during Bigboot execution:
#
# (Services listed in `bigboot_incompatible_services`
# will ALWAYS be disabled regardless if they are protected or not)
bigboot_protected_services:
- sshd.service
- user@0.service
@ -28,7 +31,7 @@ bigboot_protected_services:
- rhnsd.service
- rhnsd
- boksm.service
# - <add splunk service on wells>
- SplunkForwarder.service
# Filename of disabled services log:
bigboot_disabled_services_log: /var/ipe/ipu/el7to8/bigboot_disabled_services.log