mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Another big round of refactoring and cleaning...
This commit is contained in:
21
roles/sys-hlth-msmtp/README.md
Normal file
21
roles/sys-hlth-msmtp/README.md
Normal 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.
|
5
roles/sys-hlth-msmtp/handlers/main.yml
Normal file
5
roles/sys-hlth-msmtp/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: reload sys-hlth-msmtp.cymais.service
|
||||
systemd:
|
||||
name: sys-hlth-msmtp.cymais.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
24
roles/sys-hlth-msmtp/meta/main.yml
Normal file
24
roles/sys-hlth-msmtp/meta/main.yml
Normal 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
|
27
roles/sys-hlth-msmtp/tasks/main.yml
Normal file
27
roles/sys-hlth-msmtp/tasks/main.yml
Normal 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 }}"
|
7
roles/sys-hlth-msmtp/templates/sys-hlth-msmtp.service.j2
Normal file
7
roles/sys-hlth-msmtp/templates/sys-hlth-msmtp.service.j2
Normal 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
|
4
roles/sys-hlth-msmtp/templates/sys-hlth-msmtp.sh.j2
Normal file
4
roles/sys-hlth-msmtp/templates/sys-hlth-msmtp.sh.j2
Normal 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 }}
|
2
roles/sys-hlth-msmtp/vars/main.yml
Normal file
2
roles/sys-hlth-msmtp/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
health_msmtp_folder: '{{ path_administrator_scripts }}sys-hlth-msmtp/'
|
||||
|
Reference in New Issue
Block a user