mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Changed systemd-notifier namings
This commit is contained in:
44
roles/systemd-notifier-email/README.md
Normal file
44
roles/systemd-notifier-email/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# systemd-notifier-email Ansible Role
|
||||
|
||||
Author: Kevin Veen-Birkenbach (kevin@veen.world)
|
||||
|
||||
## Description
|
||||
|
||||
This Ansible role installs the necessary components for sending email notifications through systemd when any service fails. It configures the `systemd-notifier-email` service and handles the setup of email parameters and templates.
|
||||
|
||||
Features include:
|
||||
|
||||
- Installation and configuration of an email sending service.
|
||||
- Customizable email templates for service failure notifications.
|
||||
|
||||
This role is part of the `systemd-notifier` suite, which provides a comprehensive solution for service failure notifications in a systemd environment.
|
||||
|
||||
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).
|
||||
|
||||
## Requirements
|
||||
|
||||
This role has the following requirements:
|
||||
|
||||
- Access to an SMTP server for sending email notifications.
|
||||
- Availability of the `msmtp` package on the target system.
|
||||
|
||||
## Role Variables
|
||||
|
||||
The following variables can be customized in the role's `vars/main.yml` file:
|
||||
|
||||
- `systemd_notifier_email_folder`: The path to the folder where email-related scripts and configurations will be stored.
|
||||
|
||||
## Usage
|
||||
|
||||
To use this role, include it as a dependency in your playbook or role that requires email notifications. Ensure that the `systemd-notifier-email` role is correctly referenced and configured.
|
||||
|
||||
## License
|
||||
|
||||
This Ansible role is licensed under the AGPL v3 License. See the LICENSE file for the full license text.
|
||||
|
||||
## Contact Information
|
||||
|
||||
For any questions or feedback, please contact the author:
|
||||
|
||||
Author: Kevin Veen-Birkenbach
|
||||
Email: kevin@veen.world
|
4
roles/systemd-notifier-email/handlers/main.yml
Normal file
4
roles/systemd-notifier-email/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: "restart systemd-notifier-email service"
|
||||
systemd:
|
||||
name: systemd-notifier-email.service
|
||||
daemon_reload: yes
|
18
roles/systemd-notifier-email/tasks/main.yml
Normal file
18
roles/systemd-notifier-email/tasks/main.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
- name: install smtp-forwarder
|
||||
pacman: name=smtp-forwarder state=present
|
||||
|
||||
- name: configure msmtprc.conf.j2
|
||||
template: src=msmtprc.conf.j2 dest=/root/.msmtprc
|
||||
|
||||
- name: "create {{systemd_notifier_email_folder}}"
|
||||
file:
|
||||
path: "{{systemd_notifier_email_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: configure systemd-notifier-email.sh
|
||||
template: src=systemd-notifier-email.sh.j2 dest={{systemd_notifier_email_folder}}systemd-notifier-email.sh
|
||||
|
||||
- name: configure systemd-notifier-email.service
|
||||
template: src=systemd-notifier-email@.service.j2 dest=/etc/systemd/system/systemd-notifier-email@.service
|
||||
notify: restart systemd-notifier-email service
|
15
roles/systemd-notifier-email/templates/msmtprc.conf.j2
Normal file
15
roles/systemd-notifier-email/templates/msmtprc.conf.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
# Set default values for all following accounts.
|
||||
defaults
|
||||
auth on
|
||||
tls on
|
||||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
logfile ~/.msmtp.log
|
||||
|
||||
account system_email
|
||||
host {{system_email_host}}
|
||||
port {{system_email_port}}
|
||||
from {{system_email}}
|
||||
user {{system_email_username}}
|
||||
password {{system_email_password}}
|
||||
|
||||
account default : system_email
|
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/bin/sendmail -t <<ERRMAIL
|
||||
To: {{administrator_email}}
|
||||
From: systemd <{{system_email}}>
|
||||
Subject: $1
|
||||
Content-Transfer-Encoding: 8bit
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
$(systemctl status --full "$1")
|
||||
ERRMAIL
|
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=status email for %i to user
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{systemd_notifier_email_folder}}systemd-notifier-email.sh %i
|
||||
User=root
|
||||
Group=systemd-journal
|
1
roles/systemd-notifier-email/vars/main.yml
Normal file
1
roles/systemd-notifier-email/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
systemd_notifier_email_folder: "{{path_administrator_scripts}}systemd-notifier-email/"
|
Reference in New Issue
Block a user