ctucx.git: ansible-configs

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

commit 0d1edaf2d7a7ef7a6c5f77b5ef75defd69b2afc8
parent 3f81345537cabddf03f1e96610d92b10c9cf2138
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 11:43:56 +0100

roles/cgit: split tasks into multiple files, use handlers
8 files changed, 151 insertions(+), 144 deletions(-)
A
roles/cgit/meta/main.yml
|
6
++++++
A
roles/cgit/tasks/checks.yml
|
43
+++++++++++++++++++++++++++++++++++++++++++
A
roles/cgit/tasks/configure.yml
|
24
++++++++++++++++++++++++
A
roles/cgit/tasks/install.yml
|
8
++++++++
M
roles/cgit/tasks/main.yml
|
158
+++++++------------------------------------------------------------------------
A
roles/cgit/tasks/nginx.yml
|
16
++++++++++++++++
A
roles/cgit/tasks/remove.yml
|
30
++++++++++++++++++++++++++++++
A
roles/cgit/tasks/start.yml
|
10
++++++++++
diff --git a/roles/cgit/meta/main.yml b/roles/cgit/meta/main.yml
@@ -0,0 +1,5 @@
+---
+
+dependencies:
+  - openssh
+  - nginx-handler+
\ No newline at end of file
diff --git a/roles/cgit/tasks/checks.yml b/roles/cgit/tasks/checks.yml
@@ -0,0 +1,43 @@
+---
+
+- fail: msg="This role currently only supports AlpineLinux!"
+  when:
+    - ansible_distribution != "Alpine" 
+
+- fail: msg="Option 'services.cgit.configFile' has to be set!"
+  when:
+    - services.cgit.configFile is not defined 
+
+- fail: msg="Nginx role has to be enabled when using nginx options!"
+  when:
+    - services.cgit.nginx.enable is true
+    - services.nginx.enable is false
+
+- fail: msg="Option 'services.cgit.nginx.domain' has to be set when using nginx!"
+  when:
+    - services.cgit.nginx.enable is defined
+    - services.cgit.nginx.enable is true
+    - services.cgit.nginx.domain is not defined
+
+- fail: msg="Option 'services.cgit.nginx.sslOnly' has to be set when using nginx!"
+  when:
+    - services.cgit.nginx.enable is defined
+    - services.cgit.nginx.enable is true
+    - services.cgit.nginx.sslOnly is not defined
+
+- fail: msg="Option 'services.cgit.nginx.ssl.cert' has to be set when using nginx with ssl!"
+  when:
+    - services.cgit.nginx.enable is defined
+    - services.cgit.nginx.enable is true
+    - services.cgit.nginx.ssl.enable is defined
+    - services.cgit.nginx.ssl.enable is true
+    - services.cgit.nginx.ssl.cert is not defined
+
+- fail: msg="Option 'services.cgit.nginx.ssl.privkey' has to be set when using nginx with ssl!"
+  when:
+    - services.cgit.nginx.enable is defined
+    - services.cgit.nginx.enable is true
+    - services.cgit.nginx.ssl.enable is defined
+    - services.cgit.nginx.ssl.enable is true
+    - services.cgit.nginx.ssl.privkey is not defined
+
diff --git a/roles/cgit/tasks/configure.yml b/roles/cgit/tasks/configure.yml
@@ -0,0 +1,24 @@
+---
+
+- name: "Create fcgi-service for: cgit"
+  file:
+    src: /etc/init.d/spawn-fcgi
+    dest: /etc/init.d/spawn-fcgi.cgit
+    state: link
+  when:
+    - ansible_distribution == "Alpine"
+
+- name: "Create config for cgit's fcgi-service"
+  copy: 
+    content: "FCGI_PORT=8001\nFCGI_PROGRAM=/usr/bin/fcgiwrap"
+    dest: /etc/conf.d/spawn-fcgi.cgit
+  when:
+    - ansible_distribution == "Alpine"
+
+- name: "Copy cgitrc to: /etc/cgitrc"
+  copy: 
+    src: "{{ services.cgit.configFile }}"
+    dest: /etc/cgitrc
+    mode: 0644
+  when:
+    - services.cgit.configFile is defined
diff --git a/roles/cgit/tasks/install.yml b/roles/cgit/tasks/install.yml
@@ -0,0 +1,8 @@
+---
+
+- name: "[Alpine] Install Package(s): cgit and it's dependecys"
+  apk:
+    name: cgit git spawn-fcgi fcgiwrap py3-markdown py3-pygments
+    state: present
+  when:
+    - ansible_distribution == "Alpine"
diff --git a/roles/cgit/tasks/main.yml b/roles/cgit/tasks/main.yml
@@ -1,166 +1,36 @@
 ---
 
-# check 
-
-- fail: msg="This role currently only supports AlpineLinux!"
-  when:
-    - services.cgit.enable is true
-    - ansible_distribution != "Alpine" 
-
-- fail: msg="Option 'services.cgit.configFile' has to be set!"
-  when:
-    - services.cgit.enable is true
-    - services.cgit.configFile is not defined 
-
-- fail: msg="Nginx role has to be enabled when using nginx options!"
-  when:
-    - services.cgit.nginx.enable is true
-    - services.nginx.enable is false
-
-
-# install it 
-
-- name: "[Alpine] Install Package(s): cgit and it's dependecys"
-  apk:
-    name: cgit git spawn-fcgi fcgiwrap py3-markdown py3-pygments
-    state: present
-    update_cache: yes
-  when:
-    - services.cgit.enable is true
-    - ansible_distribution == "Alpine"
-
-
-# configure it
-
-- name: "Create fcgi-service for: cgit"
-  file:
-    src: /etc/init.d/spawn-fcgi
-    dest: /etc/init.d/spawn-fcgi.cgit
-    state: link
+- include: checks.yml
   when:
+    - services.cgit.enable is defined
     - services.cgit.enable is true
-    - ansible_distribution == "Alpine"
 
-- name: "Create config for cgit's fcgi-service"
-  copy: 
-    content: "FCGI_PORT=8001\nFCGI_PROGRAM=/usr/bin/fcgiwrap"
-    dest: /etc/conf.d/spawn-fcgi.cgit
+- include: install.yml
   when:
+    - services.cgit.enable is defined
     - services.cgit.enable is true
 
-- name: "[OpenRC] Enable and start service: spawn-fcgi.cgit"
-  service:
-    name: spawn-fcgi.cgit
-    enabled: yes
-    state: started
+- include: configure.yml
   when:
-    - ansible_service_mgr == "openrc"
+    - services.cgit.enable is defined
     - services.cgit.enable is true
 
-- name: "[nginx] Create vhost" 
-  template: 
-    src: nginx-vhost.conf.j2
-    dest: /etc/nginx/conf.d/cgit.conf
-    mode: 0644
-    owner: nginx
-    group: nginx
+- include: nginx.yml
   when:
+    - services.cgit.enable is defined
     - services.cgit.enable is true
     - services.cgit.nginx.enable is defined
     - services.cgit.nginx.enable is true
 
-- name: "Copy cgitrc to: /etc/cgitrc"
-  copy: 
-    src: "{{ services.cgit.configFile }}"
-    dest: /etc/cgitrc
-    mode: 0644
-  when:
-    - services.cgit.enable is true
-    - services.cgit.configFile is defined
-
-- name: "Copy custom css file to: /usr/share/webapps/cgit/custom-cgit.css"
-  copy: 
-    src: "{{ services.cgit.customCssFile }}"
-    dest: /usr/share/webapps/cgit/custom-cgit.css
-    mode: 0644
+- include: start.yml
   when:
+    - services.cgit.enable is defined
     - services.cgit.enable is true
-    - services.cgit.customCssFile is defined
 
-- name: Adding user nginx to group git
-  user:
-    name: nginx
-    groups: git
-    append: yes
-  when:
-    - services.cgit.enable is true
-    - services.cgit.nginx.enable is defined
-    - services.cgit.nginx.enable is true
-
-- name: "[OpenRC] Restart service: nginx"
-  service:
-    name: nginx
-    state: restarted
-  when:
-    - ansible_service_mgr == "openrc"
-    - services.cgit.enable is true
-    - services.cgit.nginx.enable is defined
-    - services.cgit.nginx.enable is true
-
-
-# remove it
-
-- name: "[OpenRC] Disable and stop service: spawn-fcgi.cgit"
-  service:
-    name: spawn-fcgi.cgit
-    enabled: no
-    state: stopped
-  when:
-    - ansible_service_mgr == "openrc"
-    - services.cgit.enable is false
-
-- name: "[Alpine] Remove Package(s): cgit and it's dependecys"
-  apk:
-    name: cgit spawn-fcgi fcgiwrap py3-markdown py3-pygments
-    state: absent
-  when:
-    - services.cgit.enable is false
-    - ansible_distribution == "Alpine"
-
-
-# remove leftover files
-
-- name: "Remove file: /etc/cgitrc"
-  file:
-    path: /etc/cgitrc
-    state: absent
-  when:
-    - services.cgit.enable is false
-
-- name: "Remove directory: /usr/share/webapps/cgit"
-  file:
-    path: /usr/share/webapps/cgit
-    state: absent
-  when:
-    - services.cgit.enable is false
-
-- name: "Remove file: /etc/conf.d/spawn-fcgi.cgit"
-  file:
-    path: /etc/conf.d/spawn-fcgi.cgit
-    state: absent
-  when:
-    - services.cgit.enable is false
-
-- name: "Remove file: /etc/init.d/spawn-fcgi.cgit"
-  file:
-    path: /etc/init.d/spawn-fcgi.cgit
-    state: absent
-  when:
-    - services.cgit.enable is false
+- name: Run handlers
+  meta: flush_handlers
 
-- name: "Remove file: /etc/nginx/conf.d/cgit.conf"
-  file:
-    path: /etc/nginx/conf.d/cgit.conf
-    state: absent
+- include: remove.yml
   when:
+    - services.cgit.enable is defined
     - services.cgit.enable is false
diff --git a/roles/cgit/tasks/nginx.yml b/roles/cgit/tasks/nginx.yml
@@ -0,0 +1,16 @@
+---
+
+- name: Adding user nginx to group git
+  user:
+    name: nginx
+    groups: git
+    append: yes
+
+- name: "[nginx] Create vhost" 
+  template: 
+    src: nginx-vhost.conf.j2
+    dest: /etc/nginx/conf.d/cgit.conf
+    mode: 0644
+    owner: nginx
+    group: nginx
+  notify: "Restart nginx"
diff --git a/roles/cgit/tasks/remove.yml b/roles/cgit/tasks/remove.yml
@@ -0,0 +1,29 @@
+---
+
+- name: "[OpenRC] Disable and stop service: spawn-fcgi.cgit"
+  service:
+    name: spawn-fcgi.cgit
+    enabled: no
+    state: stopped
+  when:
+    - ansible_service_mgr == "openrc"
+
+
+- name: "[Alpine] Remove Package(s): cgit and it's dependecys"
+  apk:
+    name: cgit spawn-fcgi fcgiwrap py3-markdown py3-pygments
+    state: absent
+  when:
+    - ansible_distribution == "Alpine"
+
+
+- name: "Delete leftovers"
+  file:
+    path: "{{item}}"
+    state: absent
+  with_items:
+    - /etc/cgitrc
+    - /usr/share/webapps/cgit
+    - /etc/conf.d/spawn-fcgi.cgit
+    - /etc/init.d/spawn-fcgi.cgit
+    - /etc/nginx/conf.d/cgit.conf+
\ No newline at end of file
diff --git a/roles/cgit/tasks/start.yml b/roles/cgit/tasks/start.yml
@@ -0,0 +1,9 @@
+---
+
+- name: "[OpenRC] Enable and start service: spawn-fcgi.cgit"
+  service:
+    name: spawn-fcgi.cgit
+    enabled: yes
+    state: started
+  when:
+    - ansible_service_mgr == "openrc"+
\ No newline at end of file