diff --git a/roles/update-docker/templates/script.py.j2 b/roles/update-docker/templates/script.py.j2 index 7e4d1bb0..eea21548 100644 --- a/roles/update-docker/templates/script.py.j2 +++ b/roles/update-docker/templates/script.py.j2 @@ -160,23 +160,6 @@ def upgrade_listmonk(): run_command('echo "y" | docker compose run -T application ./listmonk --upgrade') print("Upgrade complete.") -def update_nextcloud(): - """ - Performs the necessary Nextcloud update procedures, including maintenance and app updates. - """ - print("Start Nextcloud upgrade procedure.") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ upgrade") - print("Start Nextcloud repairing procedure.") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ maintenance:repair --include-expensive") - print("Start Nextcloud update procedure.") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ app:update --all") - print("Start Nextcloud add-missing procedure.") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ db:add-missing-columns") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ db:add-missing-indices") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ db:add-missing-primary-keys") - print("Deactivate Maintanance Mode") - update_procedure("docker-compose exec -T -u www-data application /var/www/html/occ maintenance:mode --off") - def update_procedure(command): """ Attempts to execute a command up to a maximum number of retries. @@ -239,8 +222,6 @@ if __name__ == "__main__": upgrade_listmonk() elif os.path.basename(dir_path) == "mastodon": update_mastodon() - elif os.path.basename(dir_path) == "nextcloud": - update_nextcloud() # @todo implement dedicated procedure for bluesky # @todo implement dedicated procedure for taiga diff --git a/roles/web-app-nextcloud/tasks/01_config.yml b/roles/web-app-nextcloud/tasks/01_config.yml index ce6e748c..dc4f91c1 100644 --- a/roles/web-app-nextcloud/tasks/01_config.yml +++ b/roles/web-app-nextcloud/tasks/01_config.yml @@ -19,11 +19,11 @@ - name: Copy include instructions to the container command: > - docker cp {{ nextcloud_host_include_instructions_file }} {{ nextcloud_container }}:{{ nextcloud_docker_include_instructions_file }} + docker cp {{ nextcloud_host_include_instructions_file }} {{ NEXTCLOUD_CONTAINER }}:{{ nextcloud_docker_include_instructions_file }} - name: Append generated config to config.php only if not present command: > - docker exec -u {{ nextcloud_docker_user }} {{ nextcloud_container }} sh -c " + docker exec -u {{ NEXTCLOUD_DOCKER_USER }} {{ NEXTCLOUD_CONTAINER }} sh -c " grep -q '{{ nextcloud_docker_config_additives_directory }}' {{ nextcloud_docker_config_file }} || cat {{ nextcloud_docker_include_instructions_file }} >> {{ nextcloud_docker_config_file }}" notify: docker compose restart diff --git a/roles/web-app-nextcloud/tasks/02_add_missing_indices.yml b/roles/web-app-nextcloud/tasks/02_add_missing_indices.yml deleted file mode 100644 index c158e96e..00000000 --- a/roles/web-app-nextcloud/tasks/02_add_missing_indices.yml +++ /dev/null @@ -1,15 +0,0 @@ -- name: "Add missing DB indices in Nextcloud (single run)" - ansible.builtin.shell: | - set -e - {{ nextcloud_docker_exec_occ }} db:add-missing-indices - args: - executable: /bin/bash - vars: - # Give the command enough time without async/poll overhead - ansible_command_timeout: 3600 - register: db_indices_result - failed_when: db_indices_result.rc != 0 - changed_when: > - ('Adding additional' in (db_indices_result.stdout | default(''))) or - ('Removing' in (db_indices_result.stdout | default(''))) or - ('updated successfully' in (db_indices_result.stdout | default(''))) \ No newline at end of file diff --git a/roles/web-app-nextcloud/tasks/02_upgrade.yml b/roles/web-app-nextcloud/tasks/02_upgrade.yml new file mode 100644 index 00000000..3d70013f --- /dev/null +++ b/roles/web-app-nextcloud/tasks/02_upgrade.yml @@ -0,0 +1,34 @@ +- name: Nextcloud | Upgrade + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} upgrade" + register: occ_upgrade + changed_when: "'Already up to date' not in occ_upgrade.stdout" + +- name: Nextcloud | Maintenance repair + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} maintenance:repair --include-expensive" + register: occ_repair + changed_when: "'No repairs needed' not in occ_repair.stdout" + +- name: Nextcloud | App update + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:update --all" + register: occ_app_update + changed_when: "'No apps found for update' not in occ_app_update.stdout" + +- name: Nextcloud | Add missing columns + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} db:add-missing-columns" + register: occ_columns + changed_when: "'No columns found' not in occ_columns.stdout" + +- name: Nextcloud | Add missing indices + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} db:add-missing-indices" + register: occ_indices + changed_when: "'No indices found' not in occ_indices.stdout" + +- name: Nextcloud | Add missing primary keys + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} db:add-missing-primary-keys" + register: occ_pks + changed_when: "'No primary keys found' not in occ_pks.stdout" + +- name: Nextcloud | Disable maintenance mode + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} maintenance:mode --off" + register: occ_maint_off + changed_when: "'already disabled' not in occ_maint_off.stdout" diff --git a/roles/web-app-nextcloud/tasks/03_admin.yml b/roles/web-app-nextcloud/tasks/03_admin.yml index 3fbec42b..b40d0c0e 100644 --- a/roles/web-app-nextcloud/tasks/03_admin.yml +++ b/roles/web-app-nextcloud/tasks/03_admin.yml @@ -1,6 +1,6 @@ - name: Ensure Nextcloud administrator is in the 'admin' group command: > - docker exec -u {{ nextcloud_docker_user }} {{ nextcloud_container }} + docker exec -u {{ NEXTCLOUD_DOCKER_USER }} {{ NEXTCLOUD_CONTAINER }} php occ group:adduser admin {{ nextcloud_administrator_username }} register: add_admin_to_group changed_when: "not ASYNC_ENABLED and 'Added user' in (add_admin_to_group.stdout | default(''))" diff --git a/roles/web-app-nextcloud/tasks/04_system_config.yml b/roles/web-app-nextcloud/tasks/04_system_config.yml index c755a960..62057c45 100644 --- a/roles/web-app-nextcloud/tasks/04_system_config.yml +++ b/roles/web-app-nextcloud/tasks/04_system_config.yml @@ -6,7 +6,7 @@ ansible.builtin.shell: | set -euo pipefail {% for item in nextcloud_system_config %} - {{ nextcloud_docker_exec_occ }} \ + {{ NEXTCLOUD_DOCKER_EXEC_OCC }} \ config:system:set {{ item.parameter }}{% if item.type is defined %} --type {{ item.type }}{% endif %} \ --value '{{ (item.value | string) | regex_replace("'", "'" ~ '"' ~ "'" ~ '"' ~ "'") }}' {% endfor %} diff --git a/roles/web-app-nextcloud/tasks/05_plugin.yml b/roles/web-app-nextcloud/tasks/05_plugin.yml index 0d83b3c3..532184c8 100644 --- a/roles/web-app-nextcloud/tasks/05_plugin.yml +++ b/roles/web-app-nextcloud/tasks/05_plugin.yml @@ -3,7 +3,7 @@ when: plugin_value.enabled | bool - name: disable {{ plugin_key }} nextcloud plugin - command: "{{ nextcloud_docker_exec_occ }} app:disable {{ plugin_key }}" + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:disable {{ plugin_key }}" register: disable_result changed_when: > not ASYNC_ENABLED and diff --git a/roles/web-app-nextcloud/tasks/06_plugin_routines.yml b/roles/web-app-nextcloud/tasks/06_plugin_routines.yml index 7842353d..52afcd8a 100644 --- a/roles/web-app-nextcloud/tasks/06_plugin_routines.yml +++ b/roles/web-app-nextcloud/tasks/06_plugin_routines.yml @@ -2,7 +2,7 @@ ansible.builtin.shell: | # do not set -e here; allow per-line fallbacks {% for incompatible_plugin in (plugin_value.incompatible_plugins | default([])) %} - {{ nextcloud_docker_exec_occ }} app:disable {{ incompatible_plugin }} || true + {{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:disable {{ incompatible_plugin }} || true {% endfor %} args: executable: /bin/bash @@ -22,7 +22,7 @@ poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}" - name: install {{ plugin_key }} nextcloud plugin - command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}" + command: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:install {{ plugin_key }}" register: install_result failed_when: > install_result.rc != 0 diff --git a/roles/web-app-nextcloud/tasks/07_plugin_enable_and_configure.yml b/roles/web-app-nextcloud/tasks/07_plugin_enable_and_configure.yml index 97615ab0..13f39ca6 100644 --- a/roles/web-app-nextcloud/tasks/07_plugin_enable_and_configure.yml +++ b/roles/web-app-nextcloud/tasks/07_plugin_enable_and_configure.yml @@ -1,5 +1,5 @@ - name: enable {{plugin_key}} nextcloud plugin - command: "{{nextcloud_docker_exec_occ}} app:enable {{plugin_key}}" + command: "{{NEXTCLOUD_DOCKER_EXEC_OCC}} app:enable {{plugin_key}}" register: enable_result changed_when: enable_result.rc == 0 and ("already enabled" not in enable_result.stdout) @@ -19,7 +19,7 @@ ansible.builtin.shell: | set -euo pipefail {% for item in (plugin_configuration | default([])) %} - {{ nextcloud_docker_exec_occ }} \ + {{ NEXTCLOUD_DOCKER_EXEC_OCC }} \ config:app:set {{ item.appid }} {{ item.configkey }} \ --value '{{ ( (item.configvalue | to_json) if (item.configvalue is mapping) else (item.configvalue | string) ) | regex_replace("'", "'" ~ '"' ~ "'" ~ '"' ~ "'") }}' diff --git a/roles/web-app-nextcloud/tasks/main.yml b/roles/web-app-nextcloud/tasks/main.yml index bc76edb4..5f0d496e 100644 --- a/roles/web-app-nextcloud/tasks/main.yml +++ b/roles/web-app-nextcloud/tasks/main.yml @@ -34,8 +34,8 @@ template: src: "{{ item }}" dest: "{{ nextcloud_host_config_additives_directory }}/{{ item | basename | regex_replace('\\.j2$', '') }}" - owner: "{{ nextcloud_docker_user_id }}" - group: "{{ nextcloud_docker_user_id }}" + owner: "{{ NEXTCLOUD_DOCKER_USER_id }}" + group: "{{ NEXTCLOUD_DOCKER_USER_id }}" loop: "{{ lookup('fileglob', role_path ~ '/templates/config/*.j2', wantlist=True) }}" # Not all type of changes take instantly place. Due to this reason a rebuild is required. notify: docker compose up @@ -52,10 +52,14 @@ - name: Flush all handlers immediately so that occ can be used meta: flush_handlers +- name: Update\Upgrade Nextcloud + include_tasks: 02_upgrade + when: MODE_UPDATE | bool + - name: Load system configuration steps include_tasks: "{{ item }}" loop: - - 02_add_missing_indices.yml + - 02_upgrade - 03_admin.yml - 04_system_config.yml diff --git a/roles/web-app-nextcloud/tasks/plugins/user_ldap.yml b/roles/web-app-nextcloud/tasks/plugins/user_ldap.yml index 269340c0..d58fc134 100644 --- a/roles/web-app-nextcloud/tasks/plugins/user_ldap.yml +++ b/roles/web-app-nextcloud/tasks/plugins/user_ldap.yml @@ -3,4 +3,4 @@ - name: Set Nextcloud LDAP bind password command: > - {{ nextcloud_docker_exec_occ }} ldap:set-config s01 ldapAgentPassword "{{ ldap.bind_credential }}" \ No newline at end of file + {{ NEXTCLOUD_DOCKER_EXEC_OCC }} ldap:set-config s01 ldapAgentPassword "{{ ldap.bind_credential }}" \ No newline at end of file diff --git a/roles/web-app-nextcloud/templates/docker-compose.yml.j2 b/roles/web-app-nextcloud/templates/docker-compose.yml.j2 index 1f8bb894..e70f9324 100644 --- a/roles/web-app-nextcloud/templates/docker-compose.yml.j2 +++ b/roles/web-app-nextcloud/templates/docker-compose.yml.j2 @@ -2,7 +2,7 @@ application: image: "{{ nextcloud_image }}:{{ nextcloud_version }}" - container_name: {{ nextcloud_container }} + container_name: {{ NEXTCLOUD_CONTAINER }} volumes: - data:{{ NEXTCLOUD_DOCKER_WORK_DIRECTORY }} - {{nextcloud_host_config_additives_directory}}:{{nextcloud_docker_config_additives_directory}}:ro diff --git a/roles/web-app-nextcloud/vars/main.yml b/roles/web-app-nextcloud/vars/main.yml index 9088a320..d807511f 100644 --- a/roles/web-app-nextcloud/vars/main.yml +++ b/roles/web-app-nextcloud/vars/main.yml @@ -31,7 +31,7 @@ nextcloud_volume: "{{ applications | get_app_conf( nextcloud_version: "{{ applications | get_app_conf(application_id, 'docker.services.nextcloud.version') }}" nextcloud_image: "{{ applications | get_app_conf(application_id, 'docker.services.nextcloud.image') }}" -nextcloud_container: "{{ applications | get_app_conf(application_id, 'docker.services.nextcloud.name') }}" +NEXTCLOUD_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.nextcloud.name') }}" nextcloud_proxy_name: "{{ applications | get_app_conf(application_id, 'docker.services.proxy.name') }}" nextcloud_proxy_image: "{{ applications | get_app_conf(application_id, 'docker.services.proxy.image') }}" @@ -56,8 +56,8 @@ NEXTCLOUD_COLLABORA_URL: "{{ domains | get_url('web-svc-c NEXTCLOUD_COLLABORA_ENABLED: "{{ applications | get_app_conf(application_id, 'plugins.richdocuments.enabled') }}" ## User Configuration -nextcloud_docker_user_id: 82 # UID of the www-data user -nextcloud_docker_user: "www-data" # Name of the www-data user (Set here to easy change it in the future) +NEXTCLOUD_DOCKER_USER_id: 82 # UID of the www-data user +NEXTCLOUD_DOCKER_USER: "www-data" # Name of the www-data user (Set here to easy change it in the future) ## Internal Paths NEXTCLOUD_DOCKER_WORK_DIRECTORY: "/var/www/html/" # Name of the workdir in which the application is stored @@ -67,5 +67,5 @@ nextcloud_docker_config_additives_directory: "{{ NEXTCLOUD_DOCKER_CONFIG_DIRE nextcloud_docker_include_instructions_file: "/tmp/includes.php" # Path to the temporary file which will be included to the config.php to load the additional configurations ## Execution -nextcloud_docker_exec: "docker exec -u {{ nextcloud_docker_user }} {{ nextcloud_container }}" # General execute composition -nextcloud_docker_exec_occ: "{{nextcloud_docker_exec}} {{ NEXTCLOUD_DOCKER_WORK_DIRECTORY }}occ" # Execute docker occ command \ No newline at end of file +NEXTCLOUD_DOCKER_EXEC: "docker exec -u {{ NEXTCLOUD_DOCKER_USER }} {{ NEXTCLOUD_CONTAINER }}" # General execute composition +NEXTCLOUD_DOCKER_EXEC_OCC: "{{NEXTCLOUD_DOCKER_EXEC}} {{ NEXTCLOUD_DOCKER_WORK_DIRECTORY }}occ" # Execute docker occ command \ No newline at end of file