Selaa lähdekoodia

[ntfy] Add new role

Colin Powell 3 vuotta sitten
vanhempi
commit
b30ce109d9

+ 5 - 0
ansible/hosts

@@ -25,6 +25,7 @@ redis1-master.local
 hauk1.local
 icecast1.local
 excalidraw1.local
+ntfy1.local
 test2.local
 
 [physical]
@@ -90,6 +91,7 @@ hauk1.local
 bastion1.local ansible_become=true
 icecast1.local
 excalidraw1.local
+ntfy1.local
 
 [mailinabox]
 box.unbl.ink
@@ -191,6 +193,9 @@ redis1-master.local
 [timelapse]
 timelapse.local
 
+[notify]
+ntfy1.local
+
 [test]
 test2.local
 

+ 7 - 2
ansible/playbook.yml

@@ -161,11 +161,16 @@
     - role: nginx
     - role: excalidraw
 
+- hosts: notify
+  roles:
+    - role: ntfy
+
 - hosts: test
   roles:
     - role: direnv
     - role: immortal
     - role: jails
+    - role: syncthing
     - role: tandoor
     - role: nginx
     - role: galene
@@ -187,7 +192,7 @@
     - role: icecast
     - role: hauk
     - role: miniflux
-    - role: pbp
     - role: fifteen5
-    - role: photoview
+    - role: ntfy
     - role: excalidraw
+    - role: photoview

+ 6 - 0
ansible/roles/caddy/files/Caddyfile

@@ -126,3 +126,9 @@ geoloc.unbl.ink {
 cook.unbl.ink {
     reverse_proxy tandoor.service
 }
+draw.unbl.ink {
+    reverse_proxy excalidraw.service
+}
+notify.unbl.ink {
+    reverse_proxy ntfy.service
+}

+ 42 - 0
ansible/roles/ntfy/files/ntfy.rc

@@ -0,0 +1,42 @@
+#!/bin/sh
+# Start script for FreeBSD, contributed by user Fabian Abplanalp
+# Put this script in /usr/local/etc/rc.d then adjust NTFY_BIN and
+# NTFY_CFG values in /etc/defaults/ntfy
+
+NTFY_BIN="/usr/local/bin/ntfy"
+NTFY_PID="/var/run/ntfy.pid"
+
+# Read configuration variable file if it is present
+[ -r /etc/defaults/ntfy ] && . /etc/defaults/ntfy
+
+case "$1" in
+	"start")
+		echo "Starting ntfy..."
+		${NTFY_BIN} serve &
+		echo $! >${NTFY_PID}
+		echo "done"
+		;;
+
+	"stop")
+		echo "Stopping ntfy..."
+		if [ -f ${NTFY_PID} ]; then
+			kill $(cat ${NTFY_PID})
+			rm ${NTFY_PID}
+			echo "done"
+		else
+			echo "not running?"
+		fi
+		;;
+
+	"restart")
+		echo "Restarting ntfy..."
+		$0 stop
+		sleep 2
+		$0 start
+		;;
+
+	*)
+		echo "$0 [start|stop|restart]"
+		;;
+
+esac

+ 5 - 0
ansible/roles/ntfy/handlers/main.yml

@@ -0,0 +1,5 @@
+---
+- name: Ntfy restarted
+  service:
+    name: ntfy
+    state: restarted

+ 49 - 0
ansible/roles/ntfy/tasks/main.yml

@@ -0,0 +1,49 @@
+---
+- name: Dependencies installed
+  community.general.pkgng:
+    name: git-tiny,go,python39,python39-pip,npm
+    state: latest
+  tags:
+    - build
+
+- name: Source folder exists
+  file: path=/usr/local/src mode=0755 state=directory
+  tags:
+    - build
+
+- name: Ntfy source deployed
+  git:
+    repo: "https://github.com/ntfy/ntfy.git"
+    dest: /usr/local/src/ntfy
+    force: yes
+    accept_hostkey: yes
+    update: yes
+  tags:
+    - build
+
+- name: Ntfy documentation and webapp built
+  shell:
+    chdir: /usr/local/src/ntfy
+    cmd: make docs & make web
+  tags:
+    - build
+
+- name: Ntfy binary built
+  shell:
+    chdir: /usr/local/src/ntfy
+    cmd: go install heckel.io/ntfy@latest
+
+- name: Install ntfy
+  ansible.builtin.copy:
+    src: /usr/local/src/ntfy/ntfy
+    dest: /usr/local/bin/ntfy
+    remote_src: yes
+    mode: a+x
+  notify: Ntfy restarted
+
+- name: Ntfy rc file installed
+  ansible.builtin.copy:
+    src: ntfy.rc
+    dest: /usr/local/etc/rc.d/ntfy
+    mode: a+x
+  notify: Ntfy restarted