Browse Source

Init

master
blallo 11 months ago
commit
48d940b117
Signed by: blallo GPG Key ID: 0CBE577C9B72DC3F
  1. 4
      handlers/main.yml
  2. 35
      tasks/main.yml
  3. 9
      templates/notify-failure@.service.j2
  4. 16
      templates/notify_unit_failure.sh
  5. 17
      templates/sendmail.toml.j2

4
handlers/main.yml

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

35
tasks/main.yml

@ -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

9
templates/notify-failure@.service.j2

@ -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:

16
templates/notify_unit_failure.sh

@ -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

17
templates/sendmail.toml.j2

@ -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:
Loading…
Cancel
Save