Skip to content
Snippets Groups Projects
Commit 2eb0a02c authored by nimrod's avatar nimrod
Browse files

Ansible: Add failure notification to Debian servers.

Rather cool. I've seen it before and had it on my todo list.
parent 722b5976
Branches
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Description=Docker volume backup (dvb) Description=Docker volume backup (dvb)
ConditionACPower=true ConditionACPower=true
After=local-fs.target After=local-fs.target
OnFailure=failure-notify@%n.service
[Service] [Service]
Type=exec Type=exec
......
[Unit]
Description=Failure handler for %i
[Service]
Type=oneshot
ExecStart=curl "https://notify.shore.co.il/send?message=Service%20$ifailed%20on%20%H."
[Unit]
Description=Send failure notice for %i
After=network-online.target
[Service]
Type=oneshot
ExecStart=curl https://notify.shore.co.il/send?message=Service%%20%i%%20on%%20%q%%20failed.
DynamicUser=yes
PrivateDevices=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateIPC=yes
ProtectProc=invisible
PrivateUsers=yes
...@@ -148,3 +148,42 @@ ...@@ -148,3 +148,42 @@
- toolbx - toolbx
tags: tags:
- always - always
- name: Add the failure notify service
ansible.builtin.copy:
dest: /etc/systemd/system/
group: root
mode: preserve
owner: root
src: failure-notify@.service
tags: [notify]
notify:
- Systemd daemon reload
- name: Create services drop-in directories for failure notifications
loop: &notify_failure_units
- containerd.service
- cron.service
- docker.service
- rsyslog.service
- ssh.service
- systemd-networkd.service
- systemd-timesyncd.service
- ufw.service
ansible.builtin.file:
path: /etc/systemd/system/{{ item }}.d
mode: 0o0755
state: directory
tags: [notify]
- name: Add failure notification to services
loop: *notify_failure_units
ansible.builtin.copy:
content: |
[Unit]
OnFailure=failure-notify@%n.service
dest: /etc/systemd/system/{{ item }}.d/failure-notify.conf
mode: 0o0644
tags: [notify]
notify:
- Systemd daemon reload
...@@ -60,3 +60,9 @@ ...@@ -60,3 +60,9 @@
name: '{{ item["name"] }}' name: '{{ item["name"] }}'
notify: notify:
- Systemd daemon reload - Systemd daemon reload
- name: Create the directory for service overrides
ansible.builtin.file:
mode: 0o0755
path: /etc/systemd/system/service.d
state: directory
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Description=Check btrfs device {{ device }} Description=Check btrfs device {{ device }}
After=local-fs.target After=local-fs.target
After=network-online.target After=network-online.target
OnFailure=failure-notify@%n.service
[Service] [Service]
Type=exec Type=exec
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Description=Scrub btrfs device {{ device }} Description=Scrub btrfs device {{ device }}
ConditionACPower=true ConditionACPower=true
After=local-fs.target After=local-fs.target
OnFailure=failure-notify@%n.service
[Service] [Service]
Type=exec Type=exec
......
...@@ -4,6 +4,7 @@ Description={{ description|default(name) }} ...@@ -4,6 +4,7 @@ Description={{ description|default(name) }}
ConditionACPower=true ConditionACPower=true
After=local-fs.target After=local-fs.target
After=network-online.target After=network-online.target
OnFailure=failure-notify@%n.service
[Service] [Service]
Type=exec Type=exec
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment