new service state handling

This commit is contained in:
2024-08-06 11:30:30 -04:00
parent 6fb410cffd
commit aba39cbad4
7 changed files with 108 additions and 55 deletions

53
tasks/check_services.yml Normal file
View File

@ -0,0 +1,53 @@
---
- 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 service to a list of services to disable for exceeding timeout threshold
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 service to a list of services to disable for being incompatible
ansible.builtin.set_fact:
bigboot_services_disabled: "{{ bigboot_services_disabled | default([]) + [item] }}"
loop: "{{ bigboot_incompatible_services }}"
when:
- item not in bigboot_protected_services
- ansible_facts['services'][item] is defined
- ansible_facts['services'][item]['state'] == "running"
- name: Log and disable services
ansible.builtin.include_tasks: tasks/disable_systemd_services.yml
loop: "{{ bigboot_services_disabled }}"
when:
- bigboot_services_disabled is defined
- 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(', ') }}
when:
- bigboot_services_disabled is defined
- bigboot_services_disabled | length > 0