ctucx.git: ansible-configs

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

commit 99d49d7500bf693c98d33da441679a1434739dc4
parent 828702ce1da07fcd67f804ea019be9555b555d12
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 16:56:15 +0100

roles/oeffi-web: split tasks into multiple files
6 files changed, 173 insertions(+), 0 deletions(-)
A
roles/oeffi-web/meta/main.yml
|
6
++++++
A
roles/oeffi-web/tasks/checks.yml
|
47
+++++++++++++++++++++++++++++++++++++++++++++++
A
roles/oeffi-web/tasks/install.yml
|
47
+++++++++++++++++++++++++++++++++++++++++++++++
A
roles/oeffi-web/tasks/nginx.yml
|
11
+++++++++++
A
roles/oeffi-web/tasks/remove.yml
|
47
+++++++++++++++++++++++++++++++++++++++++++++++
A
roles/oeffi-web/tasks/start.yml
|
15
+++++++++++++++
diff --git a/roles/oeffi-web/meta/main.yml b/roles/oeffi-web/meta/main.yml
@@ -0,0 +1,6 @@
+---
+
+dependencies:
+  - role: nginx
+    when:
+      - services.oeffi_web.nginx.enable is true
diff --git a/roles/oeffi-web/tasks/checks.yml b/roles/oeffi-web/tasks/checks.yml
@@ -0,0 +1,47 @@
+---
+
+- fail: msg="This role currently only supports AlpineLinux!"
+  when:
+    - ansible_distribution != "Alpine" 
+
+- fail: msg="This Role only works when Option 'system.enableOwnRepos' is true!"
+  when:
+    - system.enableOwnRepos is false
+
+- fail: msg="Option 'services.oeffi_web.instances' has to be set!"
+  when:
+    - services.oeffi_web.instances is not defined 
+
+- fail: msg="Nginx role has to be enabled when using nginx options!"
+  when:
+    - services.oeffi_web.nginx.enable is true
+    - services.nginx.enable is false
+
+- fail: msg="Option 'services.oeffi_web.nginx.domain' has to be set when using nginx!"
+  when:
+    - services.oeffi_web.nginx.enable is defined
+    - services.oeffi_web.nginx.enable is true
+    - services.oeffi_web.nginx.domain is not defined
+
+- fail: msg="Option 'services.oeffi_web.nginx.sslOnly' has to be set when using nginx!"
+  when:
+    - services.oeffi_web.nginx.enable is defined
+    - services.oeffi_web.nginx.enable is true
+    - services.oeffi_web.nginx.sslOnly is not defined
+
+- fail: msg="Option 'services.oeffi_web.nginx.ssl.cert' has to be set when using nginx with ssl!"
+  when:
+    - services.oeffi_web.nginx.enable is defined
+    - services.oeffi_web.nginx.enable is true
+    - services.oeffi_web.nginx.ssl.enable is defined
+    - services.oeffi_web.nginx.ssl.enable is true
+    - services.oeffi_web.nginx.ssl.cert is not defined
+
+- fail: msg="Option 'services.oeffi_web.nginx.ssl.privkey' has to be set when using nginx with ssl!"
+  when:
+    - services.oeffi_web.nginx.enable is defined
+    - services.oeffi_web.nginx.enable is true
+    - services.oeffi_web.nginx.ssl.enable is defined
+    - services.oeffi_web.nginx.ssl.enable is true
+    - services.oeffi_web.nginx.ssl.privkey is not defined
+
diff --git a/roles/oeffi-web/tasks/install.yml b/roles/oeffi-web/tasks/install.yml
@@ -0,0 +1,47 @@
+---
+
+- name: "[Alpine] Install package: oeffi-web"
+  apk:
+    name: oeffi-web
+    state: present
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "[OpenRC] Create service files" 
+  template: 
+    src: oeffi-web.initd.j2
+    dest: "/etc/init.d/oeffi-web{{item}}"
+    mode: 0755
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_service_mgr == "openrc"
+
+- name: "Create directory: /var/log/oeffi-web"
+  file:
+    path: "/var/log/oeffi-web"
+    mode: 0755
+    state: directory
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "Create logfiles in /var/log/oeffi-web"
+  file:
+    path: "/var/log/oeffi-web/{{item}}.log"
+    mode: 0777
+    state: touch
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_distribution == "Alpine" 
diff --git a/roles/oeffi-web/tasks/nginx.yml b/roles/oeffi-web/tasks/nginx.yml
@@ -0,0 +1,10 @@
+---
+
+- name: "[nginx] Create vhost" 
+  template: 
+    src: nginx-vhost.conf.j2
+    dest: /etc/nginx/conf.d/oeffi-web.conf
+    mode: 0644
+    owner: nginx
+    group: nginx
+  notify: "Restart nginx"+
\ No newline at end of file
diff --git a/roles/oeffi-web/tasks/remove.yml b/roles/oeffi-web/tasks/remove.yml
@@ -0,0 +1,46 @@
+---
+
+- name: "[OpenRC] Disable and stop service: oeffi-web"
+  service:
+    name: "oeffi-web{{item}}"
+    enabled: no
+    state: stopped
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_service_mgr == "openrc"
+
+- name: "[Alpine] Remove package: oeffi-web"
+  apk:
+    name: oeffi-web
+    state: absent
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "Delete files: /etc/init.d/oeffi-webX"
+  file:
+    path: "/etc/init.d/oeffi-web{{ item }}"
+    state: absent
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "Delete directory: /var/log/oeffi-web"
+  file:
+    path: /var/log/oeffi-web
+    state: absent
+  when: 
+    - ansible_distribution == "Alpine" 
+
+- name: "Delete nginx vhost for: oeffi-web"
+  file:
+    path: /etc/nginx/conf.d/oeffi-web.conf
+    state: absent
+  notify: "Restart nginx"+
\ No newline at end of file
diff --git a/roles/oeffi-web/tasks/start.yml b/roles/oeffi-web/tasks/start.yml
@@ -0,0 +1,14 @@
+---
+
+- name: "[OpenRC] Enable and start service: oeffi-web"
+  service:
+    name: "oeffi-web{{item}}"
+    enabled: yes
+    state: started
+  loop:
+    - 1
+    - 2
+    - 3
+    - 4
+  when: 
+    - ansible_service_mgr == "openrc"+
\ No newline at end of file