06_plugin.ymlยถ

---
- name: "๐Ÿ“‹ Read the apps Nextcloud has installed and enabled"
  ansible.builtin.command:
    cmd: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:list --output=json"
  register: nextcloud_app_list
  changed_when: false

- name: "๐Ÿงฎ Plan which plugins need an install, an enable or only their config"
  ansible.builtin.set_fact:
    nextcloud_plugin_plan: "{{ NEXTCLOUD_PLUGIN_ITEMS | nextcloud_plugin_plan(nextcloud_app_list.stdout | from_json) }}"
    nextcloud_plugin_configure_keys: []
    nextcloud_plugin_background_jobs: []

- name: "๐Ÿ”ด Disable the plugins that end up disabled"
  ansible.builtin.command:
    cmd: "{{ NEXTCLOUD_DOCKER_EXEC_OCC }} app:disable {{ nextcloud_plugin_plan.disable | map('quote') | join(' ') }}"
  when: nextcloud_plugin_plan.disable | length > 0
  changed_when: true

- name: "๐Ÿ“ฆ Install the plugins Nextcloud lacks, the background ones beside the loop"
  block:
    - name: "๐Ÿ›ซ Start the installs that run beside the install loop"
      ansible.builtin.include_tasks: 06_plugin/01_background.yml
      loop: "{{ NEXTCLOUD_PLUGIN_ITEMS | selectattr('key', 'in', nextcloud_plugin_plan.background) | list }}"
      loop_control:
        loop_var: plugin_item
        label: "{{ plugin_item.key }}"
      vars:
        plugin_key: "{{ plugin_item.key }}"

    - name: "๐Ÿ“ฆ Install and enable the plugins Nextcloud lacks"
      ansible.builtin.include_tasks: 06_plugin/02_install.yml
      loop: "{{ NEXTCLOUD_PLUGIN_ITEMS | selectattr('key', 'in', nextcloud_plugin_plan.install) | list }}"
      loop_control:
        loop_var: plugin_item
        label: "{{ plugin_item.key }}"
      no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
      vars:
        plugin_key: "{{ plugin_item.key }}"
        plugin_value: "{{ plugin_item.value }}"
  always:
    - name: "โณ Join the background installs"
      ansible.builtin.async_status:
        jid: "{{ item.jid }}"
      loop: "{{ nextcloud_plugin_background_jobs }}"
      loop_control:
        label: "{{ item.key }}"
      register: nextcloud_plugin_background_result
      until: nextcloud_plugin_background_result is finished
      retries: "{{ ((NEXTCLOUD_PLUGIN_BACKGROUND_ASYNC_TIME | int) / 5) | round(0, 'ceil') | int }}"
      delay: 5
      changed_when: (nextcloud_plugin_background_result | nextcloud_install_status).changed
      failed_when: nextcloud_plugin_background_result | nextcloud_background_lost

- name: "๐Ÿ“ฆ Enable and configure the plugins installed in the background"
  ansible.builtin.include_tasks: 06_plugin/02_install.yml
  loop: "{{ NEXTCLOUD_PLUGIN_ITEMS | selectattr('key', 'in', nextcloud_plugin_plan.background) | list }}"
  loop_control:
    loop_var: plugin_item
    label: "{{ plugin_item.key }}"
  no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
  vars:
    plugin_key: "{{ plugin_item.key }}"
    plugin_value: "{{ plugin_item.value }}"

- name: "๐ŸŸข Enable the installed plugins Nextcloud keeps disabled"
  ansible.builtin.include_tasks: 06_plugin/03_enable.yml
  loop: "{{ NEXTCLOUD_PLUGIN_ITEMS | selectattr('key', 'in', nextcloud_plugin_plan.enable) | list }}"
  loop_control:
    loop_var: plugin_item
    label: "{{ plugin_item.key }}"
  no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
  vars:
    plugin_key: "{{ plugin_item.key }}"
    plugin_value: "{{ plugin_item.value }}"

- name: "๐Ÿงฎ Queue the plugins Nextcloud already runs after the enabled ones"
  ansible.builtin.set_fact:
    nextcloud_plugin_configure_keys: "{{ nextcloud_plugin_configure_keys + nextcloud_plugin_plan.configure }}"

- name: "๐Ÿ”ง Configure every queued plugin in one batch"
  ansible.builtin.include_tasks: 06_plugin/04_configure.yml
  when: nextcloud_plugin_configure_keys | length > 0