Fix playbook bugs from review, add Telegram alerts to health and service checks

Review fixes:
- Availability plays: "ping_result is succeeded" is true for unreachable
  hosts, so offline hosts were added to reachable_hosts and failed the
  next play. Test reachability explicitly (7 playbooks).
- bootstrap_lxc: vim-enhanced and mtr-tiny package names, enable CRB next
  to EPEL, add the root key without replacing authorized_keys, validate
  sshd_config edits and restart sshd only on change.
- backup_docker: the command module does not expand $(...); fix rsync
  filter order and add --exclude=*; restart only the containers that were
  stopped, even when rsync fails; read the storage address from the
  inventory; keep semaphore and semaphore-db running.
- new_lxc: community.general.proxmox no longer exists, use
  community.proxmox; node is mini-pc; valid hostname; password or token
  auth; let the module pick the VMID; longer timeout.
- proxmox-backup: surface the vzdump exit code, let vzdump prune with
  keep-last, drop the rename/prune steps that globbed *.zstd.
- time-region: chrony regex no longer comments out its own server line;
  /etc/localtime as a symlink; reuse facts across plays.
- update_pihole_blocklists: FQCN, become: true, changed_when.
- ansible.cfg gathering = smart; update_system only pings ubuntu/rocky.

Telegram alerts:
- health_check: filesystems above disk_warn_pct (default 80), excluding
  efivarfs, and offline hosts.
- service_check: services not running.
- One message per run from localhost, credentials from Semaphore
  (TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID), no_log on the send task,
  prints the alert text when Telegram is not configured.

Claude-Session: https://claude.ai/code/session_01XEizHawueRXUcxQELRZ8kq
This commit is contained in:
Harwinder Sekhon
2026-09-06 23:06:18 -04:00
parent 0b7e136b24
commit 5aaa7020ac
21 changed files with 515 additions and 259 deletions
+45 -39
View File
@@ -1,30 +1,46 @@
---
- name: Configure timezone on all hosts
# Sets the timezone on every Ubuntu/Rocky guest. LXC containers share the
# host's clock, so NTP is disabled inside them; VMs sync against ntp_server.
#
# Extra vars (optional):
# timezone_region - default America/New_York
# ntp_server - default time.google.com
- name: Configure timezone
hosts: ubuntu:rocky
become: true
gather_facts: true
vars:
timezone_region: "America/New_York"
timezone_region: America/New_York
tasks:
- name: Copy timezone file
ansible.builtin.copy:
- name: Link /etc/localtime to the zoneinfo file
ansible.builtin.file:
src: "/usr/share/zoneinfo/{{ timezone_region }}"
dest: /etc/localtime
remote_src: true
state: link
force: true
- name: Write /etc/timezone
ansible.builtin.copy:
dest: /etc/timezone
content: "{{ timezone_region }}\n"
owner: root
group: root
mode: '0644'
- name: Disable NTP on Ubuntu LXC containers
# The plays below reuse the facts gathered above instead of collecting them again.
- name: NTP on Ubuntu
hosts: ubuntu
become: true
gather_facts: false
vars:
ntp_server: time.google.com
tasks:
- name: Stop and mask timesyncd on LXC
- name: Stop and mask timesyncd in LXC containers
ansible.builtin.systemd:
name: systemd-timesyncd
state: stopped
@@ -32,33 +48,11 @@
masked: true
when: ansible_virtualization_type == "lxc"
- name: Disable NTP on Rocky Linux LXC containers
hosts: rocky
become: true
tasks:
- name: Stop and mask chronyd on LXC
ansible.builtin.systemd:
name: chronyd
state: stopped
enabled: false
masked: true
when: ansible_virtualization_type == "lxc"
- name: Configure NTP on Ubuntu VMs
hosts: ubuntu
become: true
vars:
ntp_server: "time.google.com"
tasks:
- name: Configure timesyncd
- name: Point timesyncd at ntp_server on VMs
ansible.builtin.lineinfile:
path: /etc/systemd/timesyncd.conf
regexp: '^#?NTP='
line: "NTP={{ ntp_server }}"
state: present
when: ansible_virtualization_type != "lxc"
notify: Restart timesyncd
@@ -69,27 +63,38 @@
state: restarted
enabled: true
- name: Configure NTP on Rocky Linux VMs
- name: NTP on Rocky Linux
hosts: rocky
become: true
gather_facts: false
vars:
ntp_server: "time.google.com"
ntp_server: time.google.com
tasks:
- name: Disable default chrony pools
- name: Stop and mask chronyd in LXC containers
ansible.builtin.systemd:
name: chronyd
state: stopped
enabled: false
masked: true
when: ansible_virtualization_type == "lxc"
# The lookahead keeps the server line added below from being commented
# out again on the next run.
- name: Disable the default chrony pools on VMs
ansible.builtin.replace:
path: /etc/chrony.conf
regexp: '^(pool|server) .*'
replace: '# \1 removed by Ansible'
regexp: '^(pool|server)\s+(?!{{ ntp_server | regex_escape }}(\s|$)).*'
replace: '# \g<0> (disabled by Ansible)'
when: ansible_virtualization_type != "lxc"
notify: Restart chronyd
- name: Configure chrony NTP server
- name: Point chrony at ntp_server on VMs
ansible.builtin.lineinfile:
path: /etc/chrony.conf
regexp: '^server\s+{{ ntp_server | regex_escape }}(\s|$)'
line: "server {{ ntp_server }} iburst"
insertafter: EOF
state: present
when: ansible_virtualization_type != "lxc"
notify: Restart chronyd
@@ -103,6 +108,7 @@
- name: Verify time configuration
hosts: ubuntu:rocky
become: true
gather_facts: false
tasks:
- name: Check current system time