ctucx.git: ansible-configs

My personal ansible roles and playbooks

commit 7ca398cc1911695103f38dfff7d9bb9a72398c2e
parent 099602a461a055b1f1ee022a0c6c71626db5ba8b
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 21:14:06 +0100

roles/rest-server: split tasks into multiple files
8 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/roles/rest-server/handlers/main.yml b/roles/rest-server/handlers/main.yml
@@ -0,0 +1,18 @@
+---
+
+- name: "[OpenRC] Restart service: rest-server (to deploy config changes)"
+  service:
+    name: rest-server
+    state: restarted
+  when:
+    - ansible_service_mgr == "openrc"
+  listen: "Restart rest-server"
+
+- name: "[systemd] Restart service: rest-server (to deploy config changes)"
+  systemd:
+    daemon_reload: yes
+    name: rest-server
+    state: restarted
+  when:
+    - ansible_service_mgr == "systemd"
+  listen: "Restart rest-server"
diff --git a/roles/rest-server/meta/main.yml b/roles/rest-server/meta/main.yml
@@ -0,0 +1,4 @@
+---
+
+dependencies:
+  - role: nginx
diff --git a/roles/rest-server/tasks/configure.yml b/roles/rest-server/tasks/configure.yml
@@ -2,10 +2,11 @@
 
 - name: "Create directory: /var/lib/rest-server"
   file:
-    path: /var/lib/rest-server
     state: directory
+    path: /var/lib/rest-server
     owner: "{{ services.rest_server.user }}"
     group: "{{ services.rest_server.user }}"
+  notify: "Restart rest-server"
 
 - name: "[OpenRC] Create service file" 
   template:

@@ -14,6 +15,7 @@
     mode: 0755
   when:
     - ansible_service_mgr == "openrc"
+  notify: "Restart rest-server"
 
 - name: "[systemd] Create service file" 
   template:

@@ -21,4 +23,5 @@
     dest: /etc/systemd/system/rest-server.service
     mode: 0755
   when:
-    - ansible_service_mgr == "systemd"-
\ No newline at end of file
+    - ansible_service_mgr == "systemd"
+  notify: "Restart rest-server"
diff --git a/roles/rest-server/tasks/install.yml b/roles/rest-server/tasks/install.yml
@@ -4,7 +4,6 @@
   apk:
     name: rest-server
     state: present
-    update_cache: yes
   when:
     - ansible_distribution == "Alpine" 
 

@@ -12,6 +11,5 @@
   pacman:
     name: rest-server
     state: present
-    update_cache: yes
   when:
     - ansible_distribution == "Archlinux" 
diff --git a/roles/rest-server/tasks/main.yml b/roles/rest-server/tasks/main.yml
@@ -32,3 +32,4 @@
     - services.rest_server.enable is defined
     - services.rest_server.enable is false
 
+- meta: flush_handlers
diff --git a/roles/rest-server/tasks/nginx.yml b/roles/rest-server/tasks/nginx.yml
@@ -9,6 +9,7 @@
     mode: 0700
   when:
     - services.rest_server.nginx.password is defined
+  notify: "Restart nginx"
 
 - name: "[nginx] Create vhost" 
   template: 

@@ -17,17 +18,4 @@
     mode: 0644
     owner: nginx
     group: nginx
-
-- name: "[OpenRC] Restart service: nginx"
-  service:
-    name: nginx
-    state: restarted
-  when:
-    - ansible_service_mgr == "openrc"
-
-- 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/rest-server/tasks/remove.yml b/roles/rest-server/tasks/remove.yml
@@ -38,6 +38,11 @@
     state: absent
   with_items:
     - /etc/nginx/passwd/rest-server
-    - /etc/nginx/conf.d/rest-server.conf
     - /etc/systemd/system/rest-server.service
-    - /etc/init.d/rest-server-
\ No newline at end of file
+    - /etc/init.d/rest-server
+
+- name: "Delete nginx vhost for: rest-server"
+  file:
+    path: /etc/nginx/conf.d/rest-server.conf
+    state: absent
+  notify: "Restart nginx"
diff --git a/roles/rest-server/tasks/start.yml b/roles/rest-server/tasks/start.yml
@@ -8,7 +8,7 @@
   when:
     - ansible_service_mgr == "openrc"
 
-- name: "[systemd] Enable and start service: rest_server"
+- name: "[systemd] Enable and start service: rest-server"
   systemd:
     name: rest-server
     enabled: yes