feat(system_baseline): reboot one host at a time and bound a hung apt-daily.service
Add system_baseline_reboot_throttle and system_baseline_reboot_post_delay, passed to the throttle and post_reboot_delay of the reboot task, read by the main flow and by tasks_from: reboot, both defaulting to 0 (today's behaviour) and validated in both. Add system_baseline_apt_daily_timeout: when set, write a TimeoutStartSec drop-in for apt-daily.service and reload systemd. Empty by default, which leaves the host alone. Closes #336 Closes #337 Assisted-by: Claude Code
This commit is contained in:
1 parent
8da65bd08e
commit
7092d68822
14 files changed
+239
-3
No files matched your search
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# A hung apt-daily.service (a stuck mirror, a dpkg lock that never frees) blocks the next apt run on the host for as long as systemd lets
|
||||
# it start. A drop-in bounds the start. Only apt-daily.service: apt-daily-upgrade.service is left to its own timeout.
|
||||
- name: Ensure the apt-daily drop-in directory exists
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /etc/systemd/system/apt-daily.service.d
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Bound the start of apt-daily.service
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/apt-daily.service.d/10-timeout.conf
|
||||
content: |
|
||||
# Managed by Ansible (role system_baseline).
|
||||
[Service]
|
||||
TimeoutStartSec={{ system_baseline_apt_daily_timeout }}
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Reload systemd for apt-daily timeout
|
||||
@@ -32,6 +32,11 @@
|
||||
ansible.builtin.import_tasks: journald.yml
|
||||
tags: journald
|
||||
|
||||
- name: Bound a hung apt-daily.service
|
||||
ansible.builtin.import_tasks: apt_daily_timeout.yml
|
||||
when: system_baseline_apt_daily_timeout | length > 0
|
||||
tags: apt-daily-timeout
|
||||
|
||||
- name: Harden sysctl
|
||||
ansible.builtin.import_tasks: sysctl.yml
|
||||
tags: sysctl
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
---
|
||||
# The tasks_from: reboot entry point does not run validate.yml, so the reboot inputs are checked here as well.
|
||||
- name: Validate the reboot inputs
|
||||
ansible.builtin.import_tasks: validate_reboot.yml
|
||||
|
||||
- name: Check if reboot required (Debian)
|
||||
when: ansible_os_family == "Debian"
|
||||
block:
|
||||
@@ -14,6 +18,8 @@
|
||||
- name: Reboot the server if required
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 900
|
||||
post_reboot_delay: "{{ system_baseline_reboot_post_delay | int }}"
|
||||
throttle: "{{ system_baseline_reboot_throttle | int }}"
|
||||
become: true
|
||||
when:
|
||||
- system_baseline_reboot_if_required
|
||||
|
||||
@@ -39,6 +39,23 @@
|
||||
ansible.builtin.import_tasks: validate_apt_upgrade.yml
|
||||
tags: always
|
||||
|
||||
- name: Validate the reboot inputs
|
||||
ansible.builtin.import_tasks: validate_reboot.yml
|
||||
tags: always
|
||||
|
||||
# The value is written into a unit file: one line, starting with a digit, so no line break can add a second directive. systemd itself
|
||||
# refuses a value it cannot parse (it ignores the setting and logs it).
|
||||
- name: Validate the apt-daily start timeout
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_apt_daily_timeout is string
|
||||
- system_baseline_apt_daily_timeout == '' or system_baseline_apt_daily_timeout is match('^(infinity|[0-9][0-9A-Za-z. ]{0,63})\Z')
|
||||
fail_msg: >-
|
||||
system_baseline_apt_daily_timeout must be empty or a systemd time span on one line, for example 1h or 90min
|
||||
(quote a bare number: a plain 60 is not a string).
|
||||
quiet: true
|
||||
tags: always
|
||||
|
||||
# Each package pattern is written inside a double-quoted apt.conf string, like the origins below: the same characters are refused.
|
||||
- name: Validate the unattended-upgrades package blacklist
|
||||
ansible.builtin.assert:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# Shared by validate.yml and reboot.yml: the tasks_from: reboot entry point does not run validate.yml. A negative or non-integer value
|
||||
# must stop the run before a host reboots, not be coerced into a different wait. `| string` also refuses true, 2.5 and a list.
|
||||
- name: Validate the reboot throttle and post-reboot delay
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_reboot_throttle | string is match('^[0-9]+\Z')
|
||||
- system_baseline_reboot_post_delay | string is match('^[0-9]+\Z')
|
||||
fail_msg: >-
|
||||
system_baseline_reboot_throttle ('{{ system_baseline_reboot_throttle }}') and system_baseline_reboot_post_delay
|
||||
('{{ system_baseline_reboot_post_delay }}') must each be a whole number, 0 or more.
|
||||
quiet: true
|
||||
tags: always
|
||||
Reference in new issue
Block a user