ctucx.git: ansible-configs

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

commit 2d9bf27d84ab2e69129d9e415e42236e8199d210
parent 2e18cda8f8ed0e69b3d96c984c75191c65231796
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 11:40:31 +0100

roles/common: some improvements
7 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/configuration/wanderduene.yml b/configuration/wanderduene.yml
@@ -6,7 +6,7 @@ system:
   enableOwnRepos: true
   enableSudo: true
   useNTP: true #todo: support archlinux
-  enableNFS: true #todo: support archlinux
+  enableNFSMount: true #todo: support archlinux
   fstab:
     - device: UUID=fc06e9aa-37fc-45ab-ad89-4f04e8ed78ba
       path: /
diff --git a/roles/common/handlers/main.yaml b/roles/common/handlers/main.yaml
@@ -0,0 +1,34 @@
+---
+
+- name: "[Alpine/OpenRC] Restart service: networking"
+  service:
+    name: networking
+    state: restarted
+  when:
+    - ansible_service_mgr == "openrc"
+  listen: "Restart networking"
+
+- name: "[OpenRC] Restart service: chrony (to deploy config changes)"
+  service:
+    name: chrony
+    state: restarted
+  when:
+    - ansible_service_mgr == "openrc"
+  listen: "Restart chrony"
+
+
+- name: "[OpenRC] Restart service: node-exporter (to deploy config changes)"
+  service:
+    name: node-exporter
+    state: restarted
+  when:
+    - ansible_service_mgr == "openrc"
+  listen: "Restart prometheus-node-exporter"
+
+- name: "[systemd] Restart service: prometheus-node-exporter (to deploy config changes)"
+  systemd:
+    name: node-exporter
+    state: restarted
+  when:
+    - ansible_service_mgr == "systemd"
+  listen: "Restart prometheus-node-exporter"
diff --git a/roles/common/tasks/fstab.yml b/roles/common/tasks/fstab.yml
@@ -18,7 +18,7 @@
     state: started
   when:
     - ansible_service_mgr == "openrc"
-    - system.enableNFS is true
+    - system.enableNFSMount is true
 
 - name: "[OpenRC] Disable and stop service: nfsmount"
   service:

@@ -27,4 +27,4 @@
     state: stopped
   when:
     - ansible_service_mgr == "openrc"
-    - system.enableNFS is false
+    - system.enableNFSMount is false
diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml
@@ -36,3 +36,6 @@
 
 - include: node-exporter.yml
   when: services.prometheus_node_exporter is defined
+
+- name: Run handlers
+  meta: flush_handlers
diff --git a/roles/common/tasks/network_alpine.yml b/roles/common/tasks/network_alpine.yml
@@ -1,12 +1,5 @@
 ---
 
-- name: "[Alpine] create file: /etc/network/interfaces"
-  template:
-    src: interfaces.conf.j2
-    dest: /etc/network/interfaces
-    mode: 0755
-  when: network.interfaces is defined
-
 - name: "[Alpine] Install package: vlan"
   apk:
     name: vlan

@@ -43,7 +36,10 @@
     - network.bridgeSupport is defined 
     - network.bridgeSupport is false  
 
-- name: "[Alpine/OpenRC] Restart service: networking"
-  service:
-    name: networking
-    state: restarted
+- name: "[Alpine] Create file: /etc/network/interfaces"
+  template:
+    src: interfaces.conf.j2
+    dest: /etc/network/interfaces
+    mode: 0755
+  when: network.interfaces is defined
+  notify: "Restart networking"+
\ No newline at end of file
diff --git a/roles/common/tasks/node-exporter.yml b/roles/common/tasks/node-exporter.yml
@@ -7,7 +7,8 @@
     update_cache: yes
   when: 
     - ansible_distribution == "Alpine"
-    - services.prometheus_node_exporter.enable is true 
+    - services.prometheus_node_exporter.enable is true
+  notify: Restart prometheus-node-exporter
 
 - name: "[Archlinux] Install package: prometheus-node-exporter"
   pacman:

@@ -17,7 +18,7 @@
   when: 
     - ansible_distribution == "Archlinux"
     - services.prometheus_node_exporter.enable is true 
-
+  notify: Restart prometheus-node-exporter
 
 - name: "[OpenRC] Enable and start service: node-exporter"
   service:
diff --git a/roles/common/tasks/ntp.yml b/roles/common/tasks/ntp.yml
@@ -8,6 +8,7 @@
   when: 
     - ansible_distribution == "Alpine"
     - system.useNTP is true
+  notify: Restart chrony
 
 - name: "[OpenRC] Enable and start service: chrony"
   service: