ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

commit 90e99699918f3d53d2d0c11749bb42dbb07e62dd
parent d7d6a7aef242268e54899e71a96931b4ec0d698c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 21:12:10 +0100

roles/syncthing: split tasks into multiple files
8 files changed, 33 insertions(+), 70 deletions(-)
diff --git a/roles/syncthing/handlers/main.yml b/roles/syncthing/handlers/main.yml
@@ -0,0 +1,9 @@
+---
+
+- name: "[OpenRC] Restart service: syncthing-{{ services.syncthing.user }} (to deploy config changes)"
+  service:
+    name: syncthing-{{ services.syncthing.user }}
+    state: restarted
+  when:
+    - ansible_service_mgr == "openrc"
+  listen: "Restart syncthing"
diff --git a/roles/syncthing/meta/main.yml b/roles/syncthing/meta/main.yml
@@ -0,0 +1,5 @@
+---
+
+dependencies:
+  - role: nginx
+  - role: nftables-handler+
\ No newline at end of file
diff --git a/roles/syncthing/tasks/configure.yml b/roles/syncthing/tasks/configure.yml
@@ -7,3 +7,4 @@
     mode: 0755
   when: 
     - ansible_service_mgr == "openrc"
+  notify: "Restart syncthing"+
\ No newline at end of file
diff --git a/roles/syncthing/tasks/firewall.yml b/roles/syncthing/tasks/firewall.yml
@@ -4,17 +4,4 @@
   copy:
     src: nftables-rule.nft
     dest: /etc/nftables.d/syncthing.nft
-
-- name: "[OpenRC] Restart service: nftables"
-  service:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "openrc"
-
-- name: "[systemd] Restart service: nftables"
-  systemd:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "systemd"
+  notify: "Restart nftables"+
\ No newline at end of file
diff --git a/roles/syncthing/tasks/install.yml b/roles/syncthing/tasks/install.yml
@@ -4,7 +4,6 @@
   apk:
     name: syncthing
     state: present
-    update_cache: yes
   when: 
     - ansible_distribution == "Alpine" 
 

@@ -12,6 +11,5 @@
   pacman:
     name: syncthing
     state: present
-    update_cache: yes
   when: 
     - ansible_distribution == "Archlinux" 
diff --git a/roles/syncthing/tasks/main.yml b/roles/syncthing/tasks/main.yml
@@ -37,3 +37,5 @@
   when:
     - services.syncthing.enable is defined
     - services.syncthing.enable is false
+
+- meta: flush_handlers
diff --git a/roles/syncthing/tasks/nginx.yml b/roles/syncthing/tasks/nginx.yml
@@ -7,14 +7,4 @@
     mode: 0644
     owner: nginx
     group: nginx
-  when:
-    - services.syncthing.enable is true
-    - services.syncthing.nginx is defined
-    - services.syncthing.nginx.enable is true
-
-- name: "[systemd] Restart service: nginx"
-  systemd:
-    name: nginx
-    state: restarted
-  when: 
-    - ansible_service_mgr == "systemd"
+  notify: "Restart nginx"+
\ No newline at end of file
diff --git a/roles/syncthing/tasks/remove.yml b/roles/syncthing/tasks/remove.yml
@@ -17,33 +17,6 @@
     - ansible_service_mgr == "systemd"
 
 
-
-- name: "[nftables] Delete rule for: syncthing"
-  file:
-    path: /etc/nftables.d/syncthing.nft
-    state: absent
-  when: 
-    - network.nftables.enable is true
-
-- name: "[OpenRC] Restart service: nftables"
-  service:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "openrc"
-    - network.nftables.enable is true
-
-- name: "[systemd] Restart service: nftables"
-  systemd:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "systemd"
-    - network.nftables.enable is true
-
-
-
-
 - name: "[OpenRC] Disable and stop service: syncthing-{{ services.syncthing.user }}"
   service:
     name: "syncthing-{{ syncthing.user }}"

@@ -89,21 +62,15 @@
     state: absent
   with_items:
     - "/etc/init.d/syncthing-{{ services.syncthing.user }}"
-    - "/etc/nginx/conf.d/syncthing.conf"
-    - "/etc/nftables.d/syncthing.nft"
 
-- name: "[OpenRC] Restart service: nftables"
-  service:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "openrc"
-    - network.nftables.enable is true
+- name: "[nftables] Delete rule for: syncthing"
+  file:
+    path: /etc/nftables.d/syncthing.nft
+    state: absent
+  notify: "Restart nftables"
 
-- name: "[systemd] Restart service: nftables"
-  systemd:
-    name: nftables
-    state: restarted
-  when:
-    - ansible_service_mgr == "systemd"
-    - network.nftables.enable is true
+- name: "Delete nginx vhost for: syncthing"
+  file:
+    path: /etc/nginx/conf.d/syncthing.conf
+    state: absent
+  notify: "Restart nginx"