Initial project commit

This commit is contained in:
2024-12-16 19:59:57 -05:00
commit fa1b5cce00
3409 changed files with 460909 additions and 0 deletions

47
tasks/check_boot_id.yml Normal file
View File

@ -0,0 +1,47 @@
---
- name: Max check count reached
ansible.builtin.fail:
msg: "Max check count ({{ max_reboot_check }}) reached. Aborting after {{ reboot_check_count }} tries."
when:
- reboot_check_count | int >= max_reboot_check
- name: Increment check count
ansible.builtin.set_fact:
reboot_check_count: "{{ reboot_check_count | int + 1 }}"
- name: Current Iteration
ansible.builtin.debug:
msg: "{{ reboot_check_count }}"
- name: Wait for host to connect or try again
block:
- name: Wait for connection
ansible.builtin.wait_for_connection:
connect_timeout: 20
sleep: 10
delay: 70
# delay: 10
timeout: 1800
# timeout: 10
rescue:
- name: Check again - RESCUE
ansible.builtin.include_tasks: check_boot_id.yml
- name: Capture boot ID post reboot
ansible.builtin.slurp:
src: "{{ bootid_file }}"
register: post_reboot_boot_id_raw
- name: Set post-reboot boot ID
ansible.builtin.set_fact:
post_reboot_boot_id: "{{ post_reboot_boot_id_raw['content'] | b64decode | trim }}"
- name: Debug boot IDs
ansible.builtin.debug:
msg: "{{ pre_reboot_boot_id }} == {{ post_reboot_boot_id }}"
- name: Check again
ansible.builtin.include_tasks: check_boot_id.yml
when:
- pre_reboot_boot_id == post_reboot_boot_id
- reboot_check_count | int < max_reboot_check

View File

@ -0,0 +1,31 @@
---
- name: Add incompatible service to the list of services to disable if running
ansible.builtin.set_fact:
bigboot_services_disabled: "{{ bigboot_services_disabled | default([]) + [item] }}"
when:
- ansible_facts['services'][item] is defined
- ansible_facts['services'][item]['state'] == "running"
# - 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

38
tasks/check_services.yml Normal file
View File

@ -0,0 +1,38 @@
---
- 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"

View File

@ -0,0 +1,12 @@
---
- name: Check for Bigboot service state log presence
ansible.builtin.stat:
path: "{{ bigboot_disabled_services_log }}"
register: bigboot_disabled_services_log_stat
- name: Remove old Bigboot service state log
ansible.builtin.file:
path: "{{ bigboot_disabled_services_log }}"
state: absent
when:
- bigboot_disabled_services_log_stat['stat']['exists'] | bool

View File

@ -0,0 +1,43 @@
---
# - name: Disabling service for exceeding the timeout threshold
# ansible.builtin.service:
# name: "{{ item['item'] }}"
# state: stopped
# enabled: false
- name: Display service information for service being disabled
ansible.builtin.debug:
var: ansible_facts['services'][item['item']]
- name: Set up facts for service to be stopped and disabled
ansible.builtin.set_fact:
bigboot_service_to_disable:
service: "{{ ansible_facts['services'][item['item']]['name'] }}"
state: "{{ ansible_facts['services'][item['item']]['state'] == 'running' | ternary('started', 'stopped') }}"
status: "{{ ansible_facts['services'][item['item']]['status'] == 'enabled' | ternary(true, false) }}"
- name: Debug bigboot_service_to_disable
ansible.builtin.debug:
var: bigboot_service_to_disable
- name: Disabling service for exceeding the timeout threshold
ansible.builtin.debug:
msg: "{{ ansible_facts['services'][item['item']]['name'] }}"
- 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
ansible.builtin.lineinfile:
path: "{{ bigboot_disabled_services_log }}"
line: >-
{{ item['item'] }},
{{ ansible_facts['services'][item['item']]['state'] | regex_replace('running', 'started') }},
{{ ansible_facts['services'][item['item']]['status'] | regex_replace('enabled', 'true') }}
create: true
state: present
owner: root
group: root
mode: "0600"

View File

@ -0,0 +1,23 @@
---
- name: Save service state
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: Disabling service
ansible.builtin.service:
name: "{{ item }}"
state: stopped
enabled: false
- name: Log disabled service state
ansible.builtin.lineinfile:
path: "{{ bigboot_disabled_services_log }}"
line: "{{ item }},{{ bigboot_service_to_disable['state'] }},{{ bigboot_service_to_disable['status'] }}"
create: true
state: present
owner: root
group: root
mode: "0600"

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