Another big round of refactoring and cleaning...

This commit is contained in:
2025-07-11 17:55:26 +02:00
parent aa61bf2a44
commit 168c5c0da6
323 changed files with 761 additions and 811 deletions

View File

@@ -0,0 +1,21 @@
# sys-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-hlth-check script, and integrates with the **sys-alm-telegram** role. It uses the **sys-timer** role to schedule regular checks based on your customizable `OnCalendar` setting.
## Purpose
The **sys-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-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-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.

View File

@@ -0,0 +1,5 @@
- name: reload sys-hlth-msmtp.cymais.service
systemd:
name: sys-hlth-msmtp.cymais.service
enabled: yes
daemon_reload: yes

View File

@@ -0,0 +1,24 @@
---
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: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl"
min_ansible_version: "2.9"
platforms:
- name: Archlinux
versions: ["rolling"]
galaxy_tags:
- monitor
- msmtp
- email
- health
- systemd
repository: "https://s.veen.world/cymais"
documentation: "https://s.veen.world/cymais"
dependencies:
- sys-alm-telegram

View File

@@ -0,0 +1,27 @@
- name: "create {{ health_msmtp_folder }}"
file:
path: "{{ health_msmtp_folder }}"
state: directory
mode: 0755
- name: create sys-hlth-msmtp.sh
template:
src: sys-hlth-msmtp.sh.j2
dest: "{{ health_msmtp_folder }}sys-hlth-msmtp.sh"
mode: '0755'
- name: create sys-hlth-msmtp.cymais.service
template:
src: sys-hlth-msmtp.service.j2
dest: /etc/systemd/system/sys-hlth-msmtp.cymais.service
notify: reload sys-hlth-msmtp.cymais.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: "{{ on_calendar_health_msmtp }}"

View File

@@ -0,0 +1,7 @@
[Unit]
Description=Check msmtp liveliness
OnFailure=sys-alm-telegram.cymais@%n.service
[Service]
Type=oneshot
ExecStart=/bin/bash {{ health_msmtp_folder }}sys-hlth-msmtp.sh

View File

@@ -0,0 +1,4 @@
#!/bin/bash
echo "Subject: $HOST is alive
Host $HOSTNAME reports at $(date): I'm alive." | msmtp -t {{ users.administrator.email }}

View File

@@ -0,0 +1,2 @@
health_msmtp_folder: '{{ path_administrator_scripts }}sys-hlth-msmtp/'