commit 5dc83d78972360414c9b8f9d2418aa3febe17950
parent 04dee04040d12dd95ecda8d63f89fef60dbc59c3
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 17:24:29 +0100
parent 04dee04040d12dd95ecda8d63f89fef60dbc59c3
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 17:24:29 +0100
roles/oeffisearch: split tasks into multiple files
7 files changed, 188 insertions(+), 158 deletions(-)
M
|
173
+++++++------------------------------------------------------------------------
diff --git a/roles/oeffisearch/meta/main.yml b/roles/oeffisearch/meta/main.yml @@ -0,0 +1,6 @@ +--- + +dependencies: + - role: nginx + when: + - services.oeffisearch.nginx.enable is true
diff --git a/roles/oeffisearch/tasks/checks.yml b/roles/oeffisearch/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.oeffisearch.instances' has to be set!" + when: + - services.oeffisearch.instances is not defined + +- fail: msg="Nginx role has to be enabled when using nginx options!" + when: + - services.oeffisearch.nginx.enable is true + - services.nginx.enable is false + +- fail: msg="Option 'services.oeffisearch.nginx.domain' has to be set when using nginx!" + when: + - services.oeffisearch.nginx.enable is defined + - services.oeffisearch.nginx.enable is true + - services.oeffisearch.nginx.domain is not defined + +- fail: msg="Option 'services.oeffisearch.nginx.sslOnly' has to be set when using nginx!" + when: + - services.oeffisearch.nginx.enable is defined + - services.oeffisearch.nginx.enable is true + - services.oeffisearch.nginx.sslOnly is not defined + +- fail: msg="Option 'services.oeffisearch.nginx.ssl.cert' has to be set when using nginx with ssl!" + when: + - services.oeffisearch.nginx.enable is defined + - services.oeffisearch.nginx.enable is true + - services.oeffisearch.nginx.ssl.enable is defined + - services.oeffisearch.nginx.ssl.enable is true + - services.oeffisearch.nginx.ssl.cert is not defined + +- fail: msg="Option 'services.oeffisearch.nginx.ssl.privkey' has to be set when using nginx with ssl!" + when: + - services.oeffisearch.nginx.enable is defined + - services.oeffisearch.nginx.enable is true + - services.oeffisearch.nginx.ssl.enable is defined + - services.oeffisearch.nginx.ssl.enable is true + - services.oeffisearch.nginx.ssl.privkey is not defined +
diff --git a/roles/oeffisearch/tasks/install.yml b/roles/oeffisearch/tasks/install.yml @@ -0,0 +1,47 @@ +--- + +- name: "[Alpine] Install package: oeffisearch" + apk: + name: oeffisearch + state: present + when: + - ansible_distribution == "Alpine" + +- name: "[OpenRC] Create service files" + template: + src: oeffisearch.initd.j2 + dest: "/etc/init.d/oeffisearch{{item}}" + mode: 0755 + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_service_mgr == "openrc" + +- name: "Create directory: /var/log/oeffisearch" + file: + path: "/var/log/oeffisearch" + mode: 0755 + state: directory + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_distribution == "Alpine" + +- name: "Create logfiles in /var/log/oeffisearch" + file: + path: "/var/log/oeffisearch/{{item}}.log" + mode: 0777 + state: touch + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_distribution == "Alpine"
diff --git a/roles/oeffisearch/tasks/main.yml b/roles/oeffisearch/tasks/main.yml @@ -1,174 +1,31 @@ --- - -# check - -- fail: msg="This role currently only supports AlpineLinux!" +- include: checks.yml when: + - services.oeffisearch.enable is defined - services.oeffisearch.enable is true - - ansible_distribution != "Alpine" -- fail: msg="This Role only works when Option 'system.enableOwnRepos' is true!" +- include: install.yml when: + - services.oeffisearch.enable is defined - services.oeffisearch.enable is true - - system.enableOwnRepos is false - -- fail: msg="Option 'services.oeffisearch.instances' has to be set!" +- include: nginx.yml when: + - services.oeffisearch.enable is defined - services.oeffisearch.enable is true - - services.oeffisearch.instances is not defined - -- fail: msg="Nginx role has to be enabled when using nginx options!" - when: - - services.oeffisearch.nginx.enable is true - - services.nginx.enable is false - - -# install it - -- name: "[Alpine] Install package: oeffisearch" - apk: - name: oeffisearch - state: present - update_cache: yes - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is true - - -# configure it - -- name: "[OpenRC] Create service files" - template: - src: oeffisearch.initd.j2 - dest: "/etc/init.d/oeffisearch{{item}}" - mode: 0755 - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_service_mgr == "openrc" - - services.oeffisearch.enable is true - -- name: "Create directory: /var/log/oeffisearch" - file: - path: "/var/log/oeffisearch" - mode: 0755 - state: directory - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is true - -- name: "Create logfiles in /var/log/oeffisearch" - file: - path: "/var/log/oeffisearch/{{item}}.log" - mode: 0777 - state: touch - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is true - -- name: "[nginx] Create vhost" - template: - src: nginx-vhost.conf.j2 - dest: /etc/nginx/conf.d/oeffisearch.conf - mode: 0644 - owner: nginx - group: nginx - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is true + - services.oeffisearch.nginx.enable is defined - services.oeffisearch.nginx.enable is true - -# start it - -- name: "[OpenRC] Enable and restart service: oeffisearch" - service: - name: "oeffisearch{{item}}" - enabled: yes - state: restarted - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_service_mgr == "openrc" - - services.oeffisearch.enable is true - -- name: "[OpenRC] Restart service: nginx" - service: - name: nginx - state: restarted - when: - - ansible_service_mgr == "openrc" +- include: start.yml + when: + - services.oeffisearch.enable is defined - services.oeffisearch.enable is true - - services.oeffisearch.nginx.enable is true - -# remove it - -- name: "[OpenRC] Disable and stop service: oeffisearch" - service: - name: "oeffisearch{{item}}" - enabled: no - state: stopped - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_service_mgr == "openrc" - - services.oeffisearch.enable is false - -- name: "[Alpine] Remove package: oeffisearch" - apk: - name: oeffisearch - state: absent - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is false - -- name: "Delete files: /etc/init.d/oeffisearchX" - file: - path: "/etc/init.d/oeffisearch{{ item }}" - state: absent - loop: - - 1 - - 2 - - 3 - - 4 - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is false - -- name: "Delete directory: /var/log/oeffisearch" - file: - path: /var/log/oeffisearch - state: absent - when: - - ansible_distribution == "Alpine" +- include: remove.yml + when: + - services.oeffisearch.enable is defined - services.oeffisearch.enable is false -- name: "Delete file: /etc/nginx/conf.d/oeffisearch.conf" - file: - path: /etc/nginx/conf.d/oeffisearch.conf - state: absent - when: - - ansible_distribution == "Alpine" - - services.oeffisearch.enable is false +- name: Run handlers + meta: flush_handlers
diff --git a/roles/oeffisearch/tasks/nginx.yml b/roles/oeffisearch/tasks/nginx.yml @@ -0,0 +1,10 @@ +--- + +- name: "[nginx] Create vhost" + template: + src: nginx-vhost.conf.j2 + dest: /etc/nginx/conf.d/oeffisearch.conf + mode: 0644 + owner: nginx + group: nginx + notify: "Restart nginx"+ \ No newline at end of file
diff --git a/roles/oeffisearch/tasks/remove.yml b/roles/oeffisearch/tasks/remove.yml @@ -0,0 +1,46 @@ +--- + +- name: "[OpenRC] Disable and stop service: oeffisearchX" + service: + name: "oeffisearch{{item}}" + enabled: no + state: stopped + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_service_mgr == "openrc" + +- name: "[Alpine] Remove package: oeffisearch" + apk: + name: oeffisearch + state: absent + when: + - ansible_distribution == "Alpine" + +- name: "Delete files: /etc/init.d/oeffisearchX" + file: + path: "/etc/init.d/oeffisearch{{ item }}" + state: absent + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_distribution == "Alpine" + +- name: "Delete directory: /var/log/oeffisearch" + file: + path: /var/log/oeffisearch + state: absent + when: + - ansible_distribution == "Alpine" + +- name: "Delete nginx vhost for: oeffis" + file: + path: /etc/nginx/conf.d/oeffisearch.conf + state: absent + notify: "Restart nginx"+ \ No newline at end of file
diff --git a/roles/oeffisearch/tasks/start.yml b/roles/oeffisearch/tasks/start.yml @@ -0,0 +1,14 @@ +--- + +- name: "[OpenRC] Enable and start service: oeffisearch" + service: + name: "oeffisearch{{item}}" + enabled: yes + state: started + loop: + - 1 + - 2 + - 3 + - 4 + when: + - ansible_service_mgr == "openrc"+ \ No newline at end of file