nextcloud(role): remove async → use batched shell; more robust changed_when/failed_when; fix quoting; refactor plugin routines; clean up vars

• 02_add_missing_indices.yml: switched to shell (+ansible_command_timeout), removed async/poll.

• 04_system_config.yml: batch OCC calls (set -euo pipefail, /bin/bash), safer quoting, change detection via ' set to '.

• 05_plugin.yml: disable task with stricter failed_when/changed_when (combine stdout+stderr).

• 06_plugin_routines.yml: disable incompatible plugins in a single batch; no async_status; robust changed_when.

• 07_plugin_enable_and_configure.yml: batch config:app:set, safe quoting, clear changed_when/failed_when.

• config/main.yml & vars/main.yml: removed performance.async.wait_for and nextcloud_wait_for_async_enabled.
This commit is contained in:
Kevin Veen-Birkenbach 2025-08-13 18:15:50 +02:00
parent 567b1365c0
commit e2014b9b59
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
7 changed files with 60 additions and 115 deletions

View File

@ -70,8 +70,6 @@ performance:
memory_limit: "{{ ((ansible_memtotal_mb | int) / 30)|int }}M" # Dynamic set memory limit memory_limit: "{{ ((ansible_memtotal_mb | int) / 30)|int }}M" # Dynamic set memory limit
upload_limit: "5G" # Set upload limit to 5GB for big media files upload_limit: "5G" # Set upload limit to 5GB for big media files
opcache_memory_consumption: "{{ ((ansible_memtotal_mb | int) / 30)|int }}M" # Dynamic set memory consumption opcache_memory_consumption: "{{ ((ansible_memtotal_mb | int) / 30)|int }}M" # Dynamic set memory consumption
async:
wait_for: "{{ enable_debug }}" # If debug is enabled wait_for async jobs
plugins_enabled: true # Implemented for speeding up testing and debugging process. For productive environments keep it true and steer the apps via the plugins config plugins_enabled: true # Implemented for speeding up testing and debugging process. For productive environments keep it true and steer the apps via the plugins config

View File

@ -1,17 +1,13 @@
- name: "Launch async: add missing DB indices in Nextcloud" - name: "Add missing DB indices in Nextcloud (single run)"
ansible.builtin.command: > ansible.builtin.shell: |
set -e
{{ nextcloud_docker_exec_occ }} db:add-missing-indices {{ nextcloud_docker_exec_occ }} db:add-missing-indices
async: 3600 args:
poll: 0 executable: /bin/bash
register: db_indices_job vars:
# Give the command enough time without async/poll overhead
- name: "Wait for DB indices job" ansible_command_timeout: 3600
ansible.builtin.async_status:
jid: "{{ db_indices_job.ansible_job_id }}"
register: db_indices_result register: db_indices_result
until: db_indices_result.finished
retries: 600
delay: 1
failed_when: db_indices_result.rc != 0 failed_when: db_indices_result.rc != 0
changed_when: > changed_when: >
('Adding additional' in (db_indices_result.stdout | default(''))) or ('Adding additional' in (db_indices_result.stdout | default(''))) or

View File

@ -2,33 +2,18 @@
include_vars: include_vars:
file: system.yml file: system.yml
- name: "Launch async: apply Nextcloud system configs" - name: "Apply Nextcloud system configs (batched shell)"
ansible.builtin.command: > ansible.builtin.shell: |
{{ nextcloud_docker_exec_occ }} set -euo pipefail
config:system:set {{ item.parameter }} {% for item in nextcloud_system_config %}
{% if item.type is defined %} --type {{ item.type }}{% endif %} {{ nextcloud_docker_exec_occ }} \
--value {{ item.value }} config:system:set {{ item.parameter }}{% if item.type is defined %} --type {{ item.type }}{% endif %} \
loop: "{{ nextcloud_system_config }}" --value '{{ (item.value | string) | regex_replace("'", "'" ~ '"' ~ "'" ~ '"' ~ "'") }}'
loop_control: {% endfor %}
label: "{{ item.parameter }}" args:
async: 300 executable: /bin/bash
poll: 0 register: syscfg_shell
register: syscfg_jobs
- name: "Wait for system config jobs"
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
loop: "{{ syscfg_jobs.results | default([]) }}"
loop_control:
label: "{{ item._ansible_item_label | default(item.item.parameter) }}"
register: syscfg_wait
until: syscfg_wait.finished
retries: 100
delay: 1
failed_when: >
(syscfg_wait.rc is defined and syscfg_wait.rc|int != 0)
changed_when: > changed_when: >
(syscfg_wait.stdout is defined) and ( ((syscfg_shell.stdout | default('')) ~ (syscfg_shell.stderr | default('')))
("Value not changed" not in syscfg_wait.stdout) is search(' set to ') )
when: failed_when: syscfg_shell.rc != 0
- nextcloud_wait_for_async_enabled | bool

View File

@ -5,5 +5,10 @@
- name: disable {{ plugin_key }} nextcloud plugin - 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 register: disable_result
changed_when: disable_result.rc == 0 and ("No such app enabled" not in disable_result.stdout) failed_when: >
(disable_result.rc | int != 0)
and ('No such app enabled' not in (disable_result.stdout | default('') ~ disable_result.stderr | default('')))
changed_when: >
((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is search('disabled'))
and (((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is not search('already disabled')))
when: not (plugin_value.enabled | bool) when: not (plugin_value.enabled | bool)

View File

@ -1,41 +1,23 @@
# roles/web-app-nextcloud/tasks/06_plugin_routines.yml - name: "Disable incompatible plugins for {{ plugin_key }} (batched shell, no async)"
- name: "Launch async: disable incompatible plugins for {{ plugin_key }}" ansible.builtin.shell: |
ansible.builtin.command: "{{ nextcloud_docker_exec_occ }} app:disable {{ incompatible_plugin }}" # do not set -e here; allow per-line fallbacks
loop: "{{ plugin_value.incompatible_plugins }}" {% for incompatible_plugin in (plugin_value.incompatible_plugins | default([])) %}
loop_control: {{ nextcloud_docker_exec_occ }} app:disable {{ incompatible_plugin }} || true
loop_var: incompatible_plugin {% endfor %}
label: "{{ incompatible_plugin }}" args:
executable: /bin/bash
when: when:
- plugin_value.incompatible_plugins is defined - plugin_value.incompatible_plugins is defined
- plugin_value.incompatible_plugins | length > 0 - plugin_value.incompatible_plugins | length > 0
async: 180 register: disable_incompat
poll: 0
register: disable_incompat_jobs
- name: "Wait for disable jobs"
vars:
jobs_with_id: >-
{{ (disable_incompat_jobs.results | default([]))
| selectattr('ansible_job_id','defined')
| list }}
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
loop: "{{ jobs_with_id }}"
loop_control:
label: "{{ item._ansible_item_label }}"
register: disable_incompat_wait
until: disable_incompat_wait.finished
retries: 100
delay: 1
when:
- jobs_with_id | length > 0
- nextcloud_wait_for_async_enabled | bool
failed_when: >
(disable_incompat_wait.rc is defined and disable_incompat_wait.rc|int != 0)
and ('No such app enabled' not in (disable_incompat_wait.stdout | default('')))
changed_when: > changed_when: >
(disable_incompat_wait.rc | default(0) | int == 0) (((disable_incompat.stdout | default('')) ~ (disable_incompat.stderr | default('')))
and ('No such app enabled' not in (disable_incompat_wait.stdout | default(''))) is search('disabled'))
and (
(((disable_incompat.stdout | default('')) ~ (disable_incompat.stderr | default('')))
is not search('already disabled'))
)
failed_when: false
- name: install {{ plugin_key }} nextcloud plugin - name: install {{ plugin_key }} nextcloud plugin
command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}" command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}"

View File

@ -15,41 +15,22 @@
file: "{{nextcloud_control_node_plugin_vars_directory}}{{ plugin_key }}.yml" file: "{{nextcloud_control_node_plugin_vars_directory}}{{ plugin_key }}.yml"
when: plugin_vars_file.stat.exists when: plugin_vars_file.stat.exists
- name: "Launch async: set {{ item.configkey }} for {{ item.appid }}" - name: "Set plugin configuration (batched shell, no async)"
ansible.builtin.command: > ansible.builtin.shell: |
{{ nextcloud_docker_exec_occ }} config:app:set {{ item.appid }} {{ item.configkey }} set -euo pipefail
--value '{{ item.configvalue | to_json if item.configvalue is mapping else item.configvalue }}' {% for item in (plugin_configuration | default([])) %}
loop: "{{ plugin_configuration }}" {{ nextcloud_docker_exec_occ }} \
loop_control: config:app:set {{ item.appid }} {{ item.configkey }} \
label: "{{ item.appid }}:{{ item.configkey }}" --value '{{ ( (item.configvalue | to_json) if (item.configvalue is mapping) else (item.configvalue | string) )
| regex_replace("'", "'" ~ '"' ~ "'" ~ '"' ~ "'") }}'
{% endfor %}
args:
executable: /bin/bash
when: plugin_vars_file.stat.exists when: plugin_vars_file.stat.exists
async: 300 # max runtime per call (seconds) — adjust as needed register: config_set_shell
poll: 0 # don't wait; run in background
register: config_set_jobs
- name: "Wait for async jobs"
vars:
jobs_with_id: >-
{{ (config_set_jobs.results | default([]))
| selectattr('ansible_job_id','defined')
| list }}
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
register: config_set_wait
until: config_set_wait.finished
retries: 100
delay: 1
loop: "{{ jobs_with_id }}"
loop_control:
label: "{{ item._ansible_item_label | default(item.item.appid ~ ':' ~ item.item.configkey) }}"
when:
- jobs_with_id | length > 0
- nextcloud_wait_for_async_enabled | bool
failed_when: >
(config_set_wait.rc is defined and config_set_wait.rc|int != 0)
changed_when: > changed_when: >
(config_set_wait.stdout is defined) and (config_set_shell.stdout | default('')) is search(' set to ')
("Config value were not updated" not in config_set_wait.stdout) failed_when: config_set_shell.rc != 0
- name: Check if {{nextcloud_control_node_plugin_tasks_directory}}{{ plugin_key }}.yml exists - name: Check if {{nextcloud_control_node_plugin_tasks_directory}}{{ plugin_key }}.yml exists
stat: stat:

View File

@ -11,8 +11,6 @@ http_port: "{{ ports.localhost.http[applica
database_password: "{{ applications | get_app_conf(application_id, 'credentials.database_password', True)}}" database_password: "{{ applications | get_app_conf(application_id, 'credentials.database_password', True)}}"
database_type: "mariadb" # Database flavor database_type: "mariadb" # Database flavor
nextcloud_wait_for_async_enabled: "{{applications | get_app_conf(application_id, 'performance.async.wait_for')}}"
nextcloud_plugins_enabled: "{{ applications | get_app_conf(application_id, 'plugins_enabled', True) }}" nextcloud_plugins_enabled: "{{ applications | get_app_conf(application_id, 'plugins_enabled', True) }}"
nextcloud_administrator_username: "{{ applications | get_app_conf(application_id, 'users.administrator.username', True) }}" nextcloud_administrator_username: "{{ applications | get_app_conf(application_id, 'users.administrator.username', True) }}"