commit 8f3b8f7355c15a442d05fa54fe065db82ccf3d84
parent f503d5407cd6c4979f4301ee95c0c487e506f975
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 16:58:28 +0100
parent f503d5407cd6c4979f4301ee95c0c487e506f975
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 16:58:28 +0100
roles/nfsserver: split tasks into multiple files
7 files changed, 89 insertions(+), 25 deletions(-)
diff --git a/roles/nfsserver/handlers/main.yml b/roles/nfsserver/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: "Reload nfs shares" + command: + cmd: /usr/sbin/exportfs -ra" + listen: "Reload nfs shares"+ \ No newline at end of file
diff --git a/roles/nfsserver/tasks/checks.yml b/roles/nfsserver/tasks/checks.yml @@ -0,0 +1,5 @@ +--- + +- fail: msg="This role currently only supports AlpineLinux!" + when: + - ansible_distribution != "Alpine"
diff --git a/roles/nfsserver/tasks/configure.yml b/roles/nfsserver/tasks/configure.yml @@ -0,0 +1,12 @@ +--- + +- name: "[Alpine] Generate /etc/exports" + template: + src: exports.j2 + dest: /etc/exports + mode: 0755 + owner: root + group: root + notify: "Reload nfs shares" + when: + - ansible_distribution == "Alpine"
diff --git a/roles/nfsserver/tasks/install.yml b/roles/nfsserver/tasks/install.yml @@ -0,0 +1,9 @@ +--- + +- name: "[Alpine] Install package: nfs-utils" + apk: + name: nfs-utils + state: present + when: + - ansible_distribution == "Alpine" + + \ No newline at end of file
diff --git a/roles/nfsserver/tasks/main.yml b/roles/nfsserver/tasks/main.yml @@ -1,33 +1,29 @@ --- -#install it -- name: "[Alpine] Install package: nfs-utils" - apk: - name: nfs-utils - state: present - update_cache: yes - when: - - ansible_distribution == "Alpine" +- include: checks.yml + when: + - services.nfsserver.enable is defined + - services.nfsserver.enable is true + +- include: install.yml + when: + - services.nfsserver.enable is defined - services.nfsserver.enable is true -# configure it -- name: "[Alpine] Generate /etc/exports" - template: - src: exports.j2 - dest: /etc/exports - mode: 0755 - owner: root - group: root +- include: configure.yml when: - - ansible_distribution == "Alpine" + - services.nfsserver.enable is defined - services.nfsserver.enable is true -# start it -- name: "[OpenRC] Enable and start service: nfs" - service: - name: nfs - enabled: yes - state: started - when: - - ansible_service_mgr == "openrc" +- include: start.yml + when: + - services.nfsserver.enable is defined - services.nfsserver.enable is true + +- name: Run handlers + meta: flush_handlers + +- include: remove.yml + when: + - services.nfsserver.enable is defined + - services.nfsserver.enable is false
diff --git a/roles/nfsserver/tasks/remove.yml b/roles/nfsserver/tasks/remove.yml @@ -0,0 +1,25 @@ +--- + +- name: "[OpenRC] Disable and stop service: nfs" + service: + name: nfs + enabled: no + state: stopped + when: + - ansible_service_mgr == "openrc" + + +- name: "[Alpine] Remove package: nfs-utils" + apk: + name: nfs-utils + state: absent + when: + - ansible_distribution == "Alpine" + + +- name: "Delete leftovers" + file: + path: "{{item}}" + state: absent + with_items: + - /etc/exports
diff --git a/roles/nfsserver/tasks/start.yml b/roles/nfsserver/tasks/start.yml @@ -0,0 +1,9 @@ +--- + +- name: "[OpenRC] Enable and start service: nfs" + service: + name: nfs + enabled: yes + state: started + when: + - ansible_service_mgr == "openrc"