mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Refactor systemctl services and categories due to alarm bugs
This commit restructures systemctl service definitions and category mappings. Motivation: Alarm-related bugs revealed inconsistencies in service and role handling. Preparation step: lays the groundwork for fixing the alarm issues by aligning categories, roles, and service templates.
This commit is contained in:
21
roles/sys-ctl-hlth-msmtp/README.md
Normal file
21
roles/sys-ctl-hlth-msmtp/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# sys-ctl-hlth-msmtp
|
||||
|
||||
## Description
|
||||
|
||||
This Ansible role sends periodic health check emails using **msmtp** to verify that your mail transport agent is operational. It deploys a simple script and hooks it into a systemd service and timer, with failure notifications sent via Telegram.
|
||||
|
||||
## Overview
|
||||
|
||||
Optimized for Archlinux, this role creates the required directory structure, installs and configures the sys-ctl-hlth-check script, and integrates with the **sys-ctl-alm-telegram** role. It uses the **sys-timer** role to schedule regular checks based on your customizable `OnCalendar` setting.
|
||||
|
||||
## Purpose
|
||||
|
||||
The **sys-ctl-hlth-msmtp** role ensures that your mail transport system stays available by sending a test email at defined intervals. If the email fails, a Telegram alert is triggered, allowing you to detect and address issues before they impact users.
|
||||
|
||||
## Features
|
||||
|
||||
- **Directory & Script Deployment:** Sets up `sys-ctl-hlth-msmtp/` and deploys a templated Bash script to send test emails via msmtp.
|
||||
- **Systemd Service & Timer:** Provides `.service` and `.timer` units to run the check and schedule it automatically.
|
||||
- **Failure Notifications:** Leverages **sys-ctl-alm-telegram** to push alerts when the script exits with an error.
|
||||
- **Configurable Schedule:** Define your desired check frequency using the `on_calendar_health_msmtp` variable.
|
||||
- **Email Destination:** Specify the recipient via the `users.administrator.email` variable.
|
5
roles/sys-ctl-hlth-msmtp/handlers/main.yml
Normal file
5
roles/sys-ctl-hlth-msmtp/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: reload sys-ctl-hlth-msmtp service
|
||||
systemd:
|
||||
name: sys-ctl-hlth-msmtp{{ SYS_SERVICE_SUFFIX }}
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
21
roles/sys-ctl-hlth-msmtp/meta/main.yml
Normal file
21
roles/sys-ctl-hlth-msmtp/meta/main.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
galaxy_info:
|
||||
author: "Kevin Veen-Birkenbach"
|
||||
description: "Periodic MTA health-check: sends test mail via msmtp and alerts on failure."
|
||||
company: |
|
||||
Kevin Veen-Birkenbach
|
||||
Consulting & Coaching Solutions
|
||||
https://www.veen.world
|
||||
license: "Infinito.Nexus NonCommercial License"
|
||||
license_url: "https://s.infinito.nexus/license"
|
||||
min_ansible_version: "2.9"
|
||||
platforms:
|
||||
- name: Archlinux
|
||||
versions: ["rolling"]
|
||||
galaxy_tags:
|
||||
- monitor
|
||||
- msmtp
|
||||
- email
|
||||
- health
|
||||
- systemd
|
||||
repository: "https://s.infinito.nexus/code"
|
||||
documentation: "https://docs.infinito.nexus"
|
35
roles/sys-ctl-hlth-msmtp/tasks/main.yml
Normal file
35
roles/sys-ctl-hlth-msmtp/tasks/main.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
- block:
|
||||
- name: Include dependency 'sys-ctl-alm-telegram'
|
||||
include_role:
|
||||
name: sys-ctl-alm-telegram
|
||||
when: run_once_sys_ctl_alm_telegram is not defined
|
||||
- include_tasks: utils/run_once.yml
|
||||
when: run_once_sys_ctl_hlth_msmtp is not defined
|
||||
|
||||
- name: "create {{ health_msmtp_folder }}"
|
||||
file:
|
||||
path: "{{ health_msmtp_folder }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: create sys-ctl-hlth-msmtp.sh
|
||||
template:
|
||||
src: sys-ctl-hlth-msmtp.sh.j2
|
||||
dest: "{{ health_msmtp_folder }}sys-ctl-hlth-msmtp.sh"
|
||||
mode: '0755'
|
||||
|
||||
- name: create sys-ctl-hlth-msmtp{{ SYS_SERVICE_SUFFIX }}
|
||||
template:
|
||||
src: sys-ctl-hlth-msmtp.service.j2
|
||||
dest: /etc/systemd/system/sys-ctl-hlth-msmtp{{ SYS_SERVICE_SUFFIX }}
|
||||
notify: reload sys-ctl-hlth-msmtp service
|
||||
|
||||
- name: "set 'service_name' to '{{ role_name }}'"
|
||||
set_fact:
|
||||
service_name: "{{ role_name }}"
|
||||
|
||||
- name: include role for sys-timer for {{ service_name }}
|
||||
include_role:
|
||||
name: sys-timer
|
||||
vars:
|
||||
on_calendar: "{{ SYS_SCHEDULE_HEALTH_MSMTP }}"
|
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Check msmtp liveliness
|
||||
OnFailure=sys-ctl-alm-telegram.{{ SOFTWARE_NAME }}@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{ health_msmtp_folder }}sys-ctl-hlth-msmtp.sh
|
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
echo "Subject: $HOST is alive
|
||||
|
||||
Host $HOSTNAME reports at $(date): I'm alive." | msmtp -t {{ users.administrator.email }}
|
2
roles/sys-ctl-hlth-msmtp/vars/main.yml
Normal file
2
roles/sys-ctl-hlth-msmtp/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
health_msmtp_folder: '{{ PATH_ADMINISTRATOR_SCRIPTS }}sys-ctl-hlth-msmtp/'
|
||||
|
Reference in New Issue
Block a user