59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
---
|
|
- name: Verify Services
|
|
hosts: all
|
|
become: true
|
|
gather_facts: false
|
|
|
|
vars:
|
|
# value in minutes (int/float):
|
|
bigboot_service_max_timeout: 2
|
|
|
|
bigboot_protected_services:
|
|
- sshd.service
|
|
- user@0.service
|
|
|
|
tasks:
|
|
- name: Verify Middleware Apache package presence
|
|
ansible.builtin.service_facts:
|
|
|
|
- name: Debug services
|
|
ansible.builtin.debug:
|
|
var: ansible_facts.services
|
|
|
|
- name: Capture a list of running services
|
|
ansible.builtin.set_fact:
|
|
bigboot_systemd_running_services:
|
|
"{{ bigboot_systemd_running_services | default([]) + [item['key']] }}"
|
|
when:
|
|
- "'running' in item['value']['state']"
|
|
loop: "{{ ansible_facts['services'] | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item['key'] }}"
|
|
|
|
- name: Debug bigboot_systemd_running_services
|
|
ansible.builtin.debug:
|
|
var: bigboot_systemd_running_services
|
|
|
|
- name: Get timeout value for service
|
|
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: Debug bigboot_systemd_service_timeout
|
|
ansible.builtin.debug:
|
|
msg: "{{ item['item'] }} -> {{ item['stdout'] | regex_replace('^.*=(.*$)', '\\1') }}"
|
|
when:
|
|
- item['item'] not in bigboot_protected_services
|
|
- item['stdout'] | regex_replace('^.*=(.*$)', '\\1') | community.general.to_minutes >= bigboot_service_max_timeout
|
|
loop: "{{ bigboot_systemd_service_timeout['results'] }}"
|
|
loop_control:
|
|
label: "{{ item['item'] }}"
|
|
|
|
# - name: Convert a duration into minutes
|
|
# ansible.builtin.debug:
|
|
# msg: "{{ '1min 30s' | community.general.to_minutes }}"
|