ctucx.git: ansible-configs

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

commit 4326d291bce661f2253d9d9b84e1f6f62aebe3f7
parent 5a2722ad88d45d86c6ba96264aa1dae7c6a75322
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 26 Feb 2021 21:50:04 +0100

roles/vnstat: init
4 files changed, 90 insertions(+), 0 deletions(-)
A
roles/vnstat/tasks/install.yml
|
15
+++++++++++++++
A
roles/vnstat/tasks/main.yml
|
18
++++++++++++++++++
A
roles/vnstat/tasks/remove.yml
|
39
+++++++++++++++++++++++++++++++++++++++
A
roles/vnstat/tasks/start.yml
|
18
++++++++++++++++++
diff --git a/roles/vnstat/tasks/install.yml b/roles/vnstat/tasks/install.yml
@@ -0,0 +1,15 @@
+---
+
+- name: "[Alpine] Install package: vnstat"
+  apk:
+    name: vnstat
+    state: present
+  when:
+    - ansible_distribution == "Alpine" 
+
+- name: "[Archlinux] Install package: vnstat" 
+  pacman:
+    name: vnstat
+    state: present
+  when:
+    - ansible_distribution == "Archlinux" 
diff --git a/roles/vnstat/tasks/main.yml b/roles/vnstat/tasks/main.yml
@@ -0,0 +1,18 @@
+---
+
+- import_tasks: install.yml
+  when:
+    - services.vnstat.enable is defined
+    - services.vnstat.enable is true
+
+- import_tasks: start.yml
+  when:
+    - services.vnstat.enable is defined
+    - services.vnstat.enable is true
+
+- import_tasks: remove.yml
+  when:
+    - services.vnstat.enable is defined
+    - services.vnstat.enable is false
+
+- meta: flush_handlers
diff --git a/roles/vnstat/tasks/remove.yml b/roles/vnstat/tasks/remove.yml
@@ -0,0 +1,38 @@
+---
+
+- name: "[OpenRC] Disable and stop service: vnstatd"
+  service:
+    name: vnstatd
+    enabled: no
+    state: stopped
+  when:
+    - ansible_service_mgr == "openrc"
+
+- name: "[systemd] Disable and stop service: vnstat"
+  systemd:
+    name: vnstat
+    enabled: no
+    state: stopped
+  when:
+    - ansible_service_mgr == "systemd"
+
+
+- name: "[Alpine] Remove package: vnstatd" 
+  apk:
+    name: vnstatd
+    state: absent
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "[Archlinux] Remove package: vnstat"
+  pacman:
+    name: vnstat
+    state: absent
+  when: 
+    - ansible_distribution == "Archlinux" 
+
+
+- name: "Remove file: /etc/vnstat.conf"
+  file:
+    path: /etc/vnstat.conf
+    state: absent+
\ No newline at end of file
diff --git a/roles/vnstat/tasks/start.yml b/roles/vnstat/tasks/start.yml
@@ -0,0 +1,17 @@
+---
+
+- name: "[OpenRC] Start and enable service: vnstatd"
+  service:
+    name: vnstatd
+    enabled: yes
+    state: started
+  when: 
+    - ansible_service_mgr == "openrc"
+
+- name: "[systemd] Start and enable service: vnstat"
+  systemd:
+    name: vnstat
+    enabled: yes
+    state: started
+  when: 
+    - ansible_service_mgr == "systemd"+
\ No newline at end of file