Huge role refactoring/cleanup. Other commits will propably follow. Because some bugs will exist. Still important for longrun and also for auto docs/help/slideshow generation

This commit is contained in:
2025-07-08 23:43:13 +02:00
parent 6b87a049d4
commit 563d5fd528
1242 changed files with 2301 additions and 1355 deletions

View File

@@ -0,0 +1,24 @@
# Automated Email Alerts for Service Failures
## Description
This role installs and configures the necessary components for sending email notifications via systemd when a service fails. It sets up the `alert-email` service and configures email parameters and templates using msmtp.
## Overview
Optimized for secure and reliable service failure notifications, this role is an integral part of the overall `alert-core` suite. It ensures that, upon failure of a critical service, an email alert is sent automatically to enable prompt troubleshooting.
## Purpose
The primary purpose of this role is to provide a comprehensive solution for automated email notifications in a systemd environment. By integrating with msmtp and customizable templates, it delivers clear and timely alerts about service failures, thereby enhancing system reliability.
## Features
- **Service Installation & Configuration:** Installs msmtp and configures the email sending service.
- **Customizable Templates:** Supports tailoring email templates for service failure notifications.
- **Secure Notifications:** Integrates with systemd to trigger email alerts when services fail.
- **Suite Integration:** Part of the `alert-core` suite, offering a unified approach to service failure notifications.
## Other Resources
This role was created as part of a conversation with OpenAI's ChatGPT and can be found [here](https://chat.openai.com/share/96e4ca12-0888-41c0-9cfc-29c0180f0dba).

View File

@@ -0,0 +1,4 @@
- name: "restart alert-email service"
systemd:
name: alert-email.cymais.service
daemon_reload: yes

View File

@@ -0,0 +1,26 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Installs and configures components for sending email notifications. This role is part of the alert-core suite, providing automated alerts when services fail."
license: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl"
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
min_ansible_version: "2.9"
platforms:
- name: Archlinux
versions:
- rolling
galaxy_tags:
- email
- systemd
- notifications
- automation
- msmtp
repository: "https://s.veen.world/cymais"
issue_tracker_url: "https://s.veen.world/cymaisissues"
documentation: "https://s.veen.world/cymais"
dependencies:
- generic-msmtp

View File

@@ -0,0 +1,24 @@
- name: "create {{systemd_notifier_email_folder}}"
file:
path: "{{systemd_notifier_email_folder}}"
state: directory
mode: 0755
when: run_once_systemd_notifier_email is not defined
- name: configure alert-email.sh
template:
src: alert-email.sh.j2
dest: "{{systemd_notifier_email_folder}}alert-email.sh"
when: run_once_systemd_notifier_email is not defined
- name: configure alert-email.cymais.service
template:
src: alert-email@.service.j2
dest: /etc/systemd/system/alert-email.cymais@.service
notify: restart alert-email service
when: run_once_systemd_notifier_email is not defined
- name: run the systemd_notifier_email tasks once
set_fact:
run_once_systemd_notifier_email: true
when: run_once_systemd_notifier_email is not defined

View File

@@ -0,0 +1,15 @@
#!/bin/bash
/usr/bin/sendmail -t <<ERRMAIL
To: {{ users.administrator.email }}
From: systemd <{{ users['no-reply'].email }}>
Subject: $1
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
A problem with the service $1 occured:
$(systemctl status --full "$1" | head -n 30)
ERRMAIL

View File

@@ -0,0 +1,8 @@
[Unit]
Description=status email for %i to user
[Service]
Type=oneshot
ExecStart=/bin/bash {{systemd_notifier_email_folder}}alert-email.sh %i
User=root
Group=systemd-journal

View File

@@ -0,0 +1 @@
systemd_notifier_email_folder: "{{path_administrator_scripts}}alert-email/"