This commit is contained in:
sfigato 2021-02-23 18:49:29 +01:00
commit 48d940b117
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
5 changed files with 81 additions and 0 deletions

4
handlers/main.yml Normal file
View File

@ -0,0 +1,4 @@
---
- name: reload systemd
systemd:
daemon_reload: yes

35
tasks/main.yml Normal file
View File

@ -0,0 +1,35 @@
---
- name: Ensure sendmail is present
get_url:
url: "https://git.abbiamoundominio.org/blallo/sendmail/releases/download/{{ sendmail.version }}/sendmail"
dest: /usr/local/bin/sendmail
owner: root
group: root
mode: 0755
- name: Ensure sendmail template is present
template:
src: templates/sendmail.toml.j2
dest: /etc/sendmail.toml
owner: root
group: root
mode: 0644
vars:
- sections: "{{ sendmail.configuration }}"
- name: Ensure notify_unit_failure.sh is present
template:
src: templates/notify_unit_failure.sh
dest: /usr/local/bin/notify_unit_failure.sh
owner: root
group: root
mode: 0755
- name: Ensure notify-failure@.service is present
template:
src: templates/notify-failure@.service.j2
dest: /etc/systemd/system/notify-failure@.service
owner: root
group: root
mode: 0644
notify: reload systemd

View File

@ -0,0 +1,9 @@
[Unit]
Description=notify failure of %i unit via mail
[Service]
Type=oneshot
ExecStart=/usr/local/bin/notify_unit_failure.sh %i
# vim: set ft=dosini:

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
INVOCATION_ID=$(systemctl show -p InvocationID --value ${1}.service)
cat << EOM | sendmail \
-section unit_failure \
-sub "[UNIT-FAILURE|$(hostname)] ${1}"
The unit ${1}.service just failed
Date: $(date)
---
$(journalctl _SYSTEMD_INVOCATION_ID=${INVOCATION_ID})
EOM

View File

@ -0,0 +1,17 @@
{% for section in sections %}
[{{ section.name }}]
{% if section.from is defined %}
from = "{{ section.from }}"
{% endif %}
{% if section.to_list is defined %}
to = {{ section.to_list }}
{% endif %}
[{{ section.name }}.server]
address = "{{ section.server.address }}"
port = {{ section.server.port }}
user = "{{ section.server.user }}"
password = "{{ section.server.password }}"
{% endfor %}
# vim: set ft=toml et sw=0 ts=2 sts=0: