From 25c7c4a19edf7d4547a72985546441d1e359a9c2 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 10 Jul 2024 19:45:25 -0400 Subject: [PATCH] initial changes and cleanup prior to service management code --- bigboot-check-device-debug.yml | 37 +++++++++++++++++++++++++++ bigboot-noop.yml | 8 +++--- bigboot_execute_resize.yml | 3 +++ bigboot_rear_backup.yml | 20 +++++++++++---- bigboot_setup_environment.yml | 5 ++-- tasks/check_systemd_services.yml | 40 ++++++++++++++++++++++++++++++ tasks/disable_systemd_services.yml | 11 ++++++++ vars/bigboot_vars.yml | 15 +++++++++++ 8 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 bigboot-check-device-debug.yml create mode 100644 tasks/check_systemd_services.yml create mode 100644 tasks/disable_systemd_services.yml create mode 100644 vars/bigboot_vars.yml diff --git a/bigboot-check-device-debug.yml b/bigboot-check-device-debug.yml new file mode 100644 index 0000000..ac4b562 --- /dev/null +++ b/bigboot-check-device-debug.yml @@ -0,0 +1,37 @@ +--- +- name: Capture boot and logical volume information + hosts: all + become: true + gather_facts: true + strategy: free + + vars: + shrink_lv_device: "/dev/mapper/system-root" + + tasks: + - name: Get the mount point info + ansible.builtin.set_fact: + shrink_lv_mount_info: "{{ ansible_facts.mounts | selectattr('device', 'equalto', shrink_lv_device) }}" + + - name: Assert that the mount point exists + ansible.builtin.assert: + that: (shrink_lv_mount_info | length) == 1 + fail_msg: "Mount point {{ shrink_lv_device }} does not exist" + + - name: Get logical volume mount information + ansible.builtin.set_fact: + bigboot_lv_info: "{{ ansible_facts.mounts \ + | selectattr('device', 'equalto', shrink_lv_device) }}" + + - name: Assert that the mount point exists + ansible.builtin.assert: + that: (bigboot_lv_info | length) == 1 + fail_msg: "Mount point {{ shrink_lv_device }} does not exist" + + - name: Debug shrink_lv_mount_info + ansible.builtin.debug: + var: shrink_lv_mount_info + + - name: Debug bigboot_lv_info + ansible.builtin.debug: + var: bigboot_lv_info diff --git a/bigboot-noop.yml b/bigboot-noop.yml index aabe53c..2fad2aa 100644 --- a/bigboot-noop.yml +++ b/bigboot-noop.yml @@ -1,13 +1,12 @@ --- -- name: Capture boot and logical volume information +- name: Perform logical volume and boot parition resizing as needed hosts: all become: true gather_facts: true strategy: free - vars: - bigboot_size_target: 1G - + vars_files: + - bigboot_vars.yml tasks: - name: Cleanup from any previous executions @@ -24,6 +23,7 @@ ansible.builtin.import_playbook: rhc.rear.rear_backup when: - bigboot_execute_bigboot | bool + - not bigboot_skip_rear_backup | bool - name: Perform logical volume and boot parition resizing as needed diff --git a/bigboot_execute_resize.yml b/bigboot_execute_resize.yml index 20665f4..fae1638 100644 --- a/bigboot_execute_resize.yml +++ b/bigboot_execute_resize.yml @@ -5,6 +5,9 @@ gather_facts: true strategy: free + vars_files: + - bigboot_vars.yml + tasks: - name: Perform filesystem check prior to Bigboot execution when: diff --git a/bigboot_rear_backup.yml b/bigboot_rear_backup.yml index 91413de..9013549 100644 --- a/bigboot_rear_backup.yml +++ b/bigboot_rear_backup.yml @@ -1,8 +1,18 @@ --- -- 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 - - not bigboot_skip_rear_backup | bool +- name: Perform a ReaR backup + hosts: all + become: true + gather_facts: true + strategy: free + + vars_files: + - bigboot_vars.yml + + tasks: + - 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 + - not bigboot_skip_rear_backup | bool ... diff --git a/bigboot_setup_environment.yml b/bigboot_setup_environment.yml index af7e5dd..bd7dd06 100644 --- a/bigboot_setup_environment.yml +++ b/bigboot_setup_environment.yml @@ -5,9 +5,8 @@ gather_facts: true strategy: free - vars: - bigboot_size_target: 1G - ansible_ssh_retries: 10 + vars_files: + - bigboot_vars.yml tasks: - name: Cleanup from any previous executions diff --git a/tasks/check_systemd_services.yml b/tasks/check_systemd_services.yml new file mode 100644 index 0000000..e600704 --- /dev/null +++ b/tasks/check_systemd_services.yml @@ -0,0 +1,40 @@ +--- +- name: Verify Middleware Apache package presence + 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 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: Disable services exceeding the timeout threshold + when: + - item['item'] not in bigboot_protected_services + - item['stdout'] | regex_replace('^.*=(.*$)', '\\1') | community.general.to_minutes > bigboot_service_max_timeout + block: + - 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'] }}" + +- name: Re-enabling services previously disabled + ansible.builtin.service: + name: "{{ item }}" + state: started + enabled: true + loop: "{{ bigboot_systemd_disabled_services }}" diff --git a/tasks/disable_systemd_services.yml b/tasks/disable_systemd_services.yml new file mode 100644 index 0000000..d90a9f4 --- /dev/null +++ b/tasks/disable_systemd_services.yml @@ -0,0 +1,11 @@ +--- +- name: Disabling service for exceeding the timeout threshold + ansible.builtin.service: + name: "{{ item['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']] }}" diff --git a/vars/bigboot_vars.yml b/vars/bigboot_vars.yml new file mode 100644 index 0000000..082e19e --- /dev/null +++ b/vars/bigboot_vars.yml @@ -0,0 +1,15 @@ +--- +bigboot_size_target: 1G +ansible_ssh_retries: 10 + +# Max value in minutes for the timeout threshold: +bigboot_service_max_timeout: 2 + +# List of services which will be excluded from being disabled: +bigboot_protected_services: + - sshd.service + - user@0.service + - network + - rhnsd.service + # - rhnsd + - boksm.service