- name: Load System Nextcloud configuration variables
  include_vars:
    file: system.yml

- name: "Apply Nextcloud system configs (batched shell)"
  ansible.builtin.shell: |
    set -euo pipefail
    {% for item in nextcloud_system_config %}
    {{ 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 %}
  args:
    executable: /bin/bash
  register: syscfg_shell
  changed_when: >
    not ASYNC_ENABLED and
    ( ((syscfg_shell.stdout | default('')) ~ (syscfg_shell.stderr | default(''))) 
      is search(' set to ') )
  failed_when: not ASYNC_ENABLED and syscfg_shell.rc != 0
  async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
  poll:  "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
