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,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 `sys-alm-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 `sys-alm-compose` 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 `sys-alm-compose` 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 sys-alm-email service"
systemd:
name: sys-alm-email.cymais.service
daemon_reload: yes

View File

@@ -0,0 +1,27 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Installs and configures components for sending email notifications. This role is part of the sys-alm-compose 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:
- sys-svc-msmtp
- sys-rst-daemon

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 sys-alm-email.sh
template:
src: sys-alm-email.sh.j2
dest: "{{systemd_notifier_email_folder}}sys-alm-email.sh"
when: run_once_systemd_notifier_email is not defined
- name: configure sys-alm-email.cymais.service
template:
src: sys-alm-email@.service.j2
dest: /etc/systemd/system/sys-alm-email.cymais@.service
notify: restart sys-alm-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}}sys-alm-email.sh %i
User=root
Group=systemd-journal

View File

@@ -0,0 +1 @@
systemd_notifier_email_folder: '{{path_administrator_scripts}}sys-alm-email/'