From e869525f2c3549cede5b383c7b288712d457d10b Mon Sep 17 00:00:00 2001 From: Johanna Dorothea Reichmann Date: Wed, 13 Oct 2021 15:47:25 +0200 Subject: [PATCH] feat(nextcloud-apps): add role for managing nextcloud apps --- roles/nextcloud-apps/defaults/main.yml | 5 +++ roles/nextcloud-apps/handlers/main.yml | 7 ++++ roles/nextcloud-apps/tasks/main.yml | 50 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 roles/nextcloud-apps/defaults/main.yml create mode 100644 roles/nextcloud-apps/handlers/main.yml create mode 100644 roles/nextcloud-apps/tasks/main.yml diff --git a/roles/nextcloud-apps/defaults/main.yml b/roles/nextcloud-apps/defaults/main.yml new file mode 100644 index 0000000..9f2c35c --- /dev/null +++ b/roles/nextcloud-apps/defaults/main.yml @@ -0,0 +1,5 @@ +--- + +nextcloud_container_name: nextcloud +nextcloud_apps: [] +nextcloud_run_user: nextcloud diff --git a/roles/nextcloud-apps/handlers/main.yml b/roles/nextcloud-apps/handlers/main.yml new file mode 100644 index 0000000..360f780 --- /dev/null +++ b/roles/nextcloud-apps/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- name: restart-nextcloud + docker_container: + name: "{{ nextcloud_container_name }}" + state: started + restart: yes diff --git a/roles/nextcloud-apps/tasks/main.yml b/roles/nextcloud-apps/tasks/main.yml new file mode 100644 index 0000000..3934a1b --- /dev/null +++ b/roles/nextcloud-apps/tasks/main.yml @@ -0,0 +1,50 @@ +--- + +- name: Ensure nextcloud user is created + user: + name: "{{ nextcloud_run_user }}" + state: present + register: nextcloud_user_res + when: false + +- name: Install apps using php occ + community.docker.docker_container_exec: + container: "{{ nextcloud_container_name }}" + command: "php occ app:{{ verb }} {{ item.name }}" + user: "{{ nextcloud_run_user }}" + tty: yes + register: app_install_res + failed_when: "app_install_res.rc == 1 and 'already installed' not in app_install_res.stdout" + changed_when: "'already installed' not in app_install_res.stdout" + vars: + verb: >- + {%- if item.state|default('present') == 'present' -%} + install + {%- elif item.state == 'latest' -%} + update + {%- elif item.state == 'absent' -%} + remove + {%- endif -%} + loop: "{{ nextcloud_apps }}" + notify: + - restart-nextcloud + +- name: Ensure apps are enabled/disabled + community.docker.docker_container_exec: + container: "{{ nextcloud_container_name }}" + command: "php occ app:{{ verb }} {{ item.name }}" + user: "{{ nextcloud_run_user }}" + tty: yes + register: app_status_res + failed_when: "app_status_res.rc == 1 and 'No such app enabled' not in app_status_res.stdout" + changed_when: "'already enabled' not in app_status_res.stdout and 'No such app enabled' not in app_status_res.stdout" + vars: + verb: >- + {%- if item.state|default('present') in ['latest', 'present'] and item.enabled|default(True) -%} + enable + {%- elif item.enabled == False -%} + disable + {%- endif -%} + loop: "{{ nextcloud_apps }}" + notify: + - restart-nextcloud