From 6f87c559e03ad074cb042223abe480f4a6d93f7f Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 28 Aug 2022 04:01:22 +0200 Subject: [PATCH] Add systemd mails --- machine.yml | 23 +++++++++++++++++++++++ root/usr/local/bin/systemd-mail.j2 | 11 +++++++++++ 2 files changed, 34 insertions(+) create mode 100644 root/usr/local/bin/systemd-mail.j2 diff --git a/machine.yml b/machine.yml index 4c547e7..8cd3621 100644 --- a/machine.yml +++ b/machine.yml @@ -91,3 +91,26 @@ mail_postfix_install is changed or mail_postfix_cfg is changed or mail_postfix_credentials is changed + + # ---------------------------------------------------------------------------------------------- + # SystemD mails. + # ---------------------------------------------------------------------------------------------- + + - name: SystemD mail script + template: + src: ./root/usr/local/bin/systemd-mail.j2 + dest: /usr/local/bin/systemd-mail + mode: 0755 + + - name: SystemD mail service + copy: + src: ./root/etc/systemd/system/status-mail@.service + dest: /etc/systemd/system/status-mail@.service + mode: 0644 + register: systemd_status_mail_service_file + + - name: SystemD daemon reload + systemd: + daemon_reload: true + when: + systemd_status_mail_service_file is changed diff --git a/root/usr/local/bin/systemd-mail.j2 b/root/usr/local/bin/systemd-mail.j2 new file mode 100644 index 0000000..c540ed3 --- /dev/null +++ b/root/usr/local/bin/systemd-mail.j2 @@ -0,0 +1,11 @@ +#!/bin/sh + +/usr/sbin/sendmail -t < +Subject: $1 +Content-Transfer-Encoding: 8bit +Content-Type: text/plain; charset=UTF-8 + +$(systemctl status --full "$1") +SYSTEMDMAIL