From 168b729503f81413fdcc0d4de9960e8cbfabdd5a Mon Sep 17 00:00:00 2001 From: fencl Date: Sun, 5 Oct 2025 09:43:55 +0200 Subject: [PATCH] Refactor update_collabora.yml: enhance capability fetching with retries and improved error handling --- nextcloud/update_collabora.yml | 96 ++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/nextcloud/update_collabora.yml b/nextcloud/update_collabora.yml index 1e430a7..79e2499 100644 --- a/nextcloud/update_collabora.yml +++ b/nextcloud/update_collabora.yml @@ -10,6 +10,7 @@ vm_user: "{{ lookup('env', 'VM_USER') }}" vm_pass: "{{ lookup('env', 'VM_PASS') }}" use_sudo: false + collabora_caps_url: "https://collabora.martinfencl.eu/hosting/capabilities" collabora_project: "nextcloud-collabora" collabora_compose_file: "/data/compose/nextcloud/collabora-only.yml" @@ -66,39 +67,88 @@ success_msg: "All Collabora update commands succeeded." loop: "{{ collab_cmds.results }}" - # --- Fetch and show Collabora capabilities (public endpoint) --- - - name: Collabora | Fetch capabilities JSON # English comments + - name: Collabora | Grace period before capability probe # English comments + ansible.builtin.pause: + seconds: 5 + + # --- Attempt 1: fetch from controller (localhost) with retries --- + - name: Collabora | Fetch capabilities via controller (uri with retries) ansible.builtin.uri: - url: "https://collabora.martinfencl.eu/hosting/capabilities" + url: "{{ collabora_caps_url }}" method: GET return_content: true - status_code: 200 validate_certs: true - register: collab_caps + status_code: 200 # English: expect 200, anything else is "not ready yet" + register: collab_caps_uri delegate_to: localhost run_once: true + retries: 3 + delay: 3 + failed_when: false # English: do not fail the play on non-200/transport errors - - name: Collabora | Show raw capabilities payload (fallback to content if not JSON) + # --- Attempt 2 (fallback): fetch from VM via curl (often bypasses proxy/DNS quirks) --- + - name: Collabora | Fetch capabilities via VM (curl fallback) + ansible.builtin.command: + argv: + - sshpass + - -p + - "{{ vm_pass }}" + - ssh + - -o + - StrictHostKeyChecking=no + - -o + - ConnectTimeout=15 + - "{{ vm_user }}@{{ vm_ip }}" + - bash + - -lc + - > + set -euo pipefail; + curl -sSL --max-time 15 --retry 3 --retry-delay 2 + "{{ collabora_caps_url }}" + register: collab_caps_vm + changed_when: false + failed_when: false + when: collab_caps_uri.status | default(0) != 200 + + # --- Decide which payload to use (prefer uri if 200) --- + - name: Collabora | Select payload source + ansible.builtin.set_fact: + collab_caps_raw: >- + {{ + (collab_caps_uri.content + if (collab_caps_uri.status | default(0)) == 200 else + (collab_caps_vm.stdout | default(''))) + }} + + # --- Try to parse JSON; if it fails, we'll show raw --- + - name: Collabora | Parse JSON if possible + ansible.builtin.set_fact: + collab_caps_json: "{{ collab_caps_raw | from_json }}" + failed_when: false + + # --- Always show a raw payload (useful when response is HTML error like 502) --- + - name: Collabora | RAW capabilities payload ansible.builtin.debug: msg: | RAW_CAPABILITIES: - {{ (collab_caps.json | default(collab_caps.content)) }} + {{ collab_caps_raw | default('') }} - - name: Collabora | Pretty-print selected fields if JSON is available + # --- Pretty fields (only when we really got JSON) --- + - name: Collabora | Pretty-print selected fields ansible.builtin.debug: msg: | - convert-to.available: {{ collab_caps.json['convert-to']['available'] | default('n/a') }} - hasDocumentSigningSupport: {{ collab_caps.json.hasDocumentSigningSupport | default('n/a') }} - hasMobileSupport: {{ collab_caps.json.hasMobileSupport | default('n/a') }} - hasProxyPrefix: {{ collab_caps.json.hasProxyPrefix | default('n/a') }} - hasSettingIframeSupport: {{ collab_caps.json.hasSettingIframeSupport | default('n/a') }} - hasTemplateSaveAs: {{ collab_caps.json.hasTemplateSaveAs | default('n/a') }} - hasTemplateSource: {{ collab_caps.json.hasTemplateSource | default('n/a') }} - hasWASMSupport: {{ collab_caps.json.hasWASMSupport | default('n/a') }} - hasWopiAccessCheck: {{ collab_caps.json.hasWopiAccessCheck | default('n/a') }} - hasZoteroSupport: {{ collab_caps.json.hasZoteroSupport | default('n/a') }} - productName: {{ collab_caps.json.productName | default('n/a') }} - productVersion: {{ collab_caps.json.productVersion | default('n/a') }} - productVersionHash: {{ collab_caps.json.productVersionHash | default('n/a') }} - serverId: {{ collab_caps.json.serverId | default('n/a') }} - when: collab_caps.json is defined \ No newline at end of file + convert-to.available: {{ collab_caps_json['convert-to']['available'] | default('n/a') }} + hasDocumentSigningSupport: {{ collab_caps_json.hasDocumentSigningSupport | default('n/a') }} + hasMobileSupport: {{ collab_caps_json.hasMobileSupport | default('n/a') }} + hasProxyPrefix: {{ collab_caps_json.hasProxyPrefix | default('n/a') }} + hasSettingIframeSupport: {{ collab_caps_json.hasSettingIframeSupport | default('n/a') }} + hasTemplateSaveAs: {{ collab_caps_json.hasTemplateSaveAs | default('n/a') }} + hasTemplateSource: {{ collab_caps_json.hasTemplateSource | default('n/a') }} + hasWASMSupport: {{ collab_caps_json.hasWASMSupport | default('n/a') }} + hasWopiAccessCheck: {{ collab_caps_json.hasWopiAccessCheck | default('n/a') }} + hasZoteroSupport: {{ collab_caps_json.hasZoteroSupport | default('n/a') }} + productName: {{ collab_caps_json.productName | default('n/a') }} + productVersion: {{ collab_caps_json.productVersion | default('n/a') }} + productVersionHash: {{ collab_caps_json.productVersionHash | default('n/a') }} + serverId: {{ collab_caps_json.serverId | default('n/a') }} + when: collab_caps_json is defined \ No newline at end of file