ctucx.git: ansible-configs

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

commit 8c51cdf37faafecb6568ce5e9e4d2f50e64a1b0a
parent e500f10a4bd2360e318926959c89022a942aea18
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 21:13:08 +0100

roles/postgresql: split tasks into multiple files
4 files changed, 66 insertions(+), 71 deletions(-)
A
roles/postgresql/tasks/install.yml
|
15
+++++++++++++++
M
roles/postgresql/tasks/main.yml
|
74
+++-----------------------------------------------------------------------
A
roles/postgresql/tasks/remove.yml
|
31
+++++++++++++++++++++++++++++++
A
roles/postgresql/tasks/start.yml
|
17
+++++++++++++++++
diff --git a/roles/postgresql/tasks/install.yml b/roles/postgresql/tasks/install.yml
@@ -0,0 +1,15 @@
+---
+
+- name: "[Alpine] Install package: postgresql"
+  apk:
+    name: postgresql postgresql-contrib
+    state: present
+  when:
+    - ansible_distribution == "Alpine" 
+
+- name: "[Archlinux] Install package: postgresql"
+  pacman:
+    name: postgresql postgresql-contrib
+    state: present
+  when:
+    - ansible_distribution == "Archlinux" 
diff --git a/roles/postgresql/tasks/main.yml b/roles/postgresql/tasks/main.yml
@@ -1,84 +1,16 @@
 ---
 
-- name: "[Alpine] Install package: postgresql"
-  apk:
-    name: postgresql postgresql-contrib
-    state: present
-    update_cache: yes  
+- include: install.yml
   when:
-    - ansible_distribution == "Alpine" 
     - services.postgresql.enable is defined
     - services.postgresql.enable is true
 
-- name: "[Archlinux] Install package: postgresql"
-  pacman:
-    name: postgresql postgresql-contrib
-    state: present
-    update_cache: yes  
+- include: start.yml
   when:
-    - ansible_distribution == "Archlinux" 
     - services.postgresql.enable is defined
     - services.postgresql.enable is true
 
-
-- name: "[OpenRC] Enable and start service: postgresql"
-  service:
-    name: postgresql
-    enabled: yes
-    state: started
-  when:
-    - ansible_service_mgr == "openrc"
-    - services.postgresql.enable is defined
-    - services.postgresql.enable is true
-
-- name: "[systemd] Enable and start service: postgresql"
-  systemd:
-    name: postgresql
-    enabled: yes
-    state: started
-  when:
-    - ansible_service_mgr == "systemd"
-    - services.postgresql.enable is defined
-    - services.postgresql.enable is true
-
-
-
-
-
-- name: "[OpenRC] Disable and stop service: postgresql"
-  service:
-    name: postgresql
-    enabled: no
-    state: stopped
-  when:
-    - ansible_service_mgr == "openrc"
-    - services.postgresql.enable is defined
-    - services.postgresql.enable is false
-
-- name: "[systemd] Disable and stop service: postgresql"
-  systemd:
-    name: postgresql
-    enabled: no
-    state: stopped
-  when:
-    - ansible_service_mgr == "systemd"
-    - services.postgresql.enable is defined
-    - services.postgresql.enable is false
-
-- name: "[Alpine] Remove package: postgresql"
-  apk:
-    name: postgresql postgresql-contrib
-    state: absent
-  when:
-    - ansible_distribution == "Alpine" 
-    - services.postgresql.enable is defined
-    - services.postgresql.enable is false
-
-- name: "[Archlinux] Remove package: postgresql"
-  pacman:
-    name: postgresql postgresql-contrib
-    state: absent
+- include: remove.yml
   when:
-    - ansible_distribution == "Archlinux" 
     - services.postgresql.enable is defined
     - services.postgresql.enable is false
diff --git a/roles/postgresql/tasks/remove.yml b/roles/postgresql/tasks/remove.yml
@@ -0,0 +1,31 @@
+---
+
+- name: "[OpenRC] Disable and stop service: postgresql"
+  service:
+    name: postgresql
+    enabled: no
+    state: stopped
+  when:
+    - ansible_service_mgr == "openrc"
+
+- name: "[systemd] Disable and stop service: postgresql"
+  systemd:
+    name: postgresql
+    enabled: no
+    state: stopped
+  when:
+    - ansible_service_mgr == "systemd"
+
+- name: "[Alpine] Remove package: postgresql"
+  apk:
+    name: postgresql postgresql-contrib
+    state: absent
+  when:
+    - ansible_distribution == "Alpine" 
+
+- name: "[Archlinux] Remove package: postgresql"
+  pacman:
+    name: postgresql postgresql-contrib
+    state: absent
+  when:
+    - ansible_distribution == "Archlinux" 
diff --git a/roles/postgresql/tasks/start.yml b/roles/postgresql/tasks/start.yml
@@ -0,0 +1,17 @@
+---
+
+- name: "[OpenRC] Enable and start service: postgresql"
+  service:
+    name: postgresql
+    enabled: yes
+    state: started
+  when:
+    - ansible_service_mgr == "openrc"
+
+- name: "[systemd] Enable and start service: postgresql"
+  systemd:
+    name: postgresql
+    enabled: yes
+    state: started
+  when:
+    - ansible_service_mgr == "systemd"