From b834c2e4c4060c07be0c4bfffd17d260dd5659fd Mon Sep 17 00:00:00 2001 From: fencl Date: Sun, 5 Oct 2025 15:45:37 +0200 Subject: [PATCH] . --- nextcloud/update_collabora.yml | 12 +- nextcloud/update_uptime_kuma_.yml | 167 ------------------ ..._uptime_kuma.yml => update_uptime_kuma.yml | 14 +- 3 files changed, 19 insertions(+), 174 deletions(-) delete mode 100644 nextcloud/update_uptime_kuma_.yml rename nextcloud/update_uptime_kuma.yml => update_uptime_kuma.yml (91%) diff --git a/nextcloud/update_collabora.yml b/nextcloud/update_collabora.yml index 73d99dc..ae4dbae 100644 --- a/nextcloud/update_collabora.yml +++ b/nextcloud/update_collabora.yml @@ -14,6 +14,9 @@ vm_pass: "{{ lookup('env', 'VM_PASS') }}" use_sudo: false + # --- Debug mode (controlled via Semaphore variable) --- + DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}" + # --- Collabora specifics --- collabora_debug_caps: true collabora_caps_url: "https://collabora.martinfencl.eu/hosting/capabilities" @@ -57,6 +60,7 @@ loop: "{{ collabora_commands }}" register: collab_cmds changed_when: false + no_log: "{{ DEBUG == 0 }}" # 🔒 Hide sensitive info when DEBUG=0 - name: Show outputs for each Collabora command ansible.builtin.debug: @@ -68,6 +72,7 @@ STDERR: {{ (item.stderr | default('')).strip() }} loop: "{{ collab_cmds.results }}" + when: DEBUG == 1 # 🪵 Only show debug output if DEBUG=1 - name: Fail play if any Collabora command failed ansible.builtin.assert: @@ -123,6 +128,7 @@ changed_when: false failed_when: false when: caps_controller.status | default(0) != 200 or caps_controller.json is not defined + no_log: "{{ DEBUG == 0 }}" # 🔒 Hide command and output when not debugging - name: Collabora | Choose JSON (controller wins, else VM) ansible.builtin.set_fact: @@ -145,15 +151,15 @@ ({{ collab_caps_json.productName | default('?') }}), convert-to.available={{ collab_caps_json['convert-to']['available'] | default('n/a') }}, serverId={{ collab_caps_json.serverId | default('n/a') }} - when: collab_caps_json is defined + when: collab_caps_json is defined and DEBUG == 1 # 🪵 Only print in debug mode - name: Collabora | Capabilities unavailable (after retries) ansible.builtin.debug: msg: "Capabilities endpoint není dostupný ani po pokusech." - when: collab_caps_json is not defined + when: collab_caps_json is not defined and DEBUG == 1 # Optional full JSON (debug) - name: Collabora | Full JSON (debug) ansible.builtin.debug: var: collab_caps_json - when: collabora_debug_caps and (collab_caps_json is defined) + when: collabora_debug_caps and (collab_caps_json is defined) and DEBUG == 1 # 🪵 Only when debugging diff --git a/nextcloud/update_uptime_kuma_.yml b/nextcloud/update_uptime_kuma_.yml deleted file mode 100644 index 97a1ff4..0000000 --- a/nextcloud/update_uptime_kuma_.yml +++ /dev/null @@ -1,167 +0,0 @@ -- name: Update Uptime Kuma on VM via Proxmox - hosts: proxmox - gather_facts: false - become: true - become_user: root - become_method: sudo - - vars: - # VM connection (provided by Semaphore env vars) - vm_ip: "{{ lookup('env', 'VM_IP') }}" - vm_user: "{{ lookup('env', 'VM_USER') }}" - vm_pass: "{{ lookup('env', 'VM_PASS') }}" - use_sudo: false - - # Uptime Kuma specifics - kuma_project: "uptime-kuma" - kuma_compose_file: "/data/compose/uptime-kuma.yml" - kuma_service: "uptime-kuma" - kuma_image: "louislam/uptime-kuma:latest" - kuma_port: 3001 - - # Optional external URL for controller-side readiness check (e.g., https://kuma.example.com) - # If empty/undefined, controller check is skipped and we only probe from the VM. - kuma_url: "{{ lookup('env', 'KUMA_URL') | default('', true) }}" - - # Fixed container name used in your compose (conflicts with previous/Portainer-run container) - kuma_container_name: "uptime-kuma-dev" - - # Docker command prefix (consistent behavior) - docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker" - - # Commands to run on the target VM (quiet outputs like in Collabora play) - kuma_commands: - - "{{ docker_prefix }} pull -q {{ kuma_image }} >/dev/null" - - "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} pull {{ kuma_service }} >/dev/null" - # --- added: gently remove conflicting container name before compose up --- - - "{{ docker_prefix }} rm -f {{ kuma_container_name }} >/dev/null 2>&1 || true" - # ------------------------------------------------------------------------ - - "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} up -d --no-deps --force-recreate {{ kuma_service }} >/dev/null" - - tasks: - - name: Ensure sshpass is installed (for password-based SSH) # English comments - ansible.builtin.apt: - name: sshpass - state: present - update_cache: yes - - - name: Run Uptime Kuma update commands on VM (via SSH) - ansible.builtin.command: - argv: - - sshpass - - -p - - "{{ vm_pass }}" - - ssh - - -o - - StrictHostKeyChecking=no - - -o - - ConnectTimeout=15 - - "{{ vm_user }}@{{ vm_ip }}" - - bash - - -lc - - "{{ ('sudo ' if use_sudo else '') + item }}" - loop: "{{ kuma_commands }}" - register: kuma_cmds - changed_when: false - - - name: Show outputs for each Uptime Kuma command - ansible.builtin.debug: - msg: | - CMD: {{ item.item }} - RC: {{ item.rc }} - STDOUT: - {{ (item.stdout | default('')).strip() }} - STDERR: - {{ (item.stderr | default('')).strip() }} - loop: "{{ kuma_cmds.results }}" - - - name: Fail play if any Uptime Kuma command failed - ansible.builtin.assert: - that: "item.rc == 0" - fail_msg: "Uptime Kuma update failed on VM: {{ item.item }} (rc={{ item.rc }})" - success_msg: "All Uptime Kuma update commands succeeded." - loop: "{{ kuma_cmds.results }}" - - # ------------------------- - # Readiness checks (controller first, then VM fallback) - # ------------------------- - - - name: Kuma | Wait for homepage (controller first) - ansible.builtin.uri: - url: "{{ (kuma_url | regex_replace('/$','')) + '/' }}" - method: GET - return_content: true - # Validate TLS only when using https:// - validate_certs: "{{ (kuma_url | default('')) is match('^https://') }}" - status_code: 200 - register: kuma_controller - delegate_to: localhost - run_once: true - when: kuma_url is defined and (kuma_url | length) > 0 - retries: 10 - delay: 2 - until: kuma_controller.status == 200 - failed_when: false - changed_when: false - - - name: Kuma | VM-side fetch (HTML via Python) - ansible.builtin.command: - argv: - - sshpass - - -p - - "{{ vm_pass }}" - - ssh - - -o - - StrictHostKeyChecking=no - - -o - - ConnectTimeout=15 - - "{{ vm_user }}@{{ vm_ip }}" - - bash - - -lc - - | - python3 - <<'PY' - # Fetch Kuma homepage from localhost and print HTML to stdout - import urllib.request, sys - try: - with urllib.request.urlopen("http://127.0.0.1:{{ kuma_port }}/", timeout=15) as r: - sys.stdout.write(r.read().decode(errors='ignore')) - except Exception: - pass - PY - register: kuma_vm - changed_when: false - failed_when: false - when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined - - - name: Kuma | Choose homepage HTML (controller wins, else VM) - ansible.builtin.set_fact: - kuma_home_html: >- - {{ - (kuma_controller.content - if (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined) - else ( - (kuma_vm.stdout | default('') | trim | length > 0) - | ternary((kuma_vm.stdout | trim), omit) - ) - ) - }} - failed_when: false - - - name: Kuma | Print concise summary - ansible.builtin.debug: - msg: >- - Uptime Kuma homepage {{ 'reachable' if (kuma_home_html is defined) else 'NOT reachable' }}. - Source={{ 'controller' if ((kuma_controller.status|default(0))==200 and (kuma_controller.content is defined)) else 'vm' if (kuma_vm.stdout|default('')|trim|length>0) else 'n/a' }}; - length={{ (kuma_home_html | default('')) | length }}; - contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }} - - - name: Kuma | Homepage unavailable (after retries) - ansible.builtin.debug: - msg: "Kuma web není dostupná ani po pokusech." - when: kuma_home_html is not defined - - # Optional detailed dump (short excerpt only) - - name: Kuma | HTML excerpt (debug) - ansible.builtin.debug: - msg: "{{ (kuma_home_html | default(''))[:500] }}" - when: kuma_home_html is defined diff --git a/nextcloud/update_uptime_kuma.yml b/update_uptime_kuma.yml similarity index 91% rename from nextcloud/update_uptime_kuma.yml rename to update_uptime_kuma.yml index c59b674..569a590 100644 --- a/nextcloud/update_uptime_kuma.yml +++ b/update_uptime_kuma.yml @@ -14,6 +14,9 @@ vm_pass: "{{ lookup('env', 'VM_PASS') }}" use_sudo: false + # --- Debug mode (controlled via Semaphore variable) --- + DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}" + # Uptime Kuma specifics kuma_project: "uptime-kuma" kuma_compose_file: "/data/compose/uptime-kuma.yml" @@ -28,7 +31,7 @@ # Fixed container name used in your compose (conflicts with previous/Portainer-run container) kuma_container_name: "uptime-kuma-dev" - # Retry policy (to mirror Collabora play): 10x with 2s delay + # Retry policy (to mirror Collabora play): 25x with 2s delay kuma_retries: 25 kuma_delay: 2 @@ -68,6 +71,7 @@ loop: "{{ kuma_commands }}" register: kuma_cmds changed_when: false + no_log: "{{ DEBUG == 0 }}" # 🔒 Hide sensitive info when not debugging - name: Show outputs for each Uptime Kuma command ansible.builtin.debug: @@ -79,6 +83,7 @@ STDERR: {{ (item.stderr | default('')).strip() }} loop: "{{ kuma_cmds.results }}" + when: DEBUG == 1 # 🪵 Only show debug output if DEBUG=1 - name: Fail play if any Uptime Kuma command failed ansible.builtin.assert: @@ -139,8 +144,8 @@ when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined retries: "{{ kuma_retries }}" delay: "{{ kuma_delay }}" - # Wait until we actually got some HTML that likely belongs to Kuma until: (kuma_vm.stdout | default('') | trim | length) > 0 and ('Uptime Kuma' in (kuma_vm.stdout | default(''))) + no_log: "{{ DEBUG == 0 }}" # 🔒 Hide command and output when not debugging - name: Kuma | Choose homepage HTML (controller wins, else VM) # safe guard against empty result ansible.builtin.set_fact: @@ -166,14 +171,15 @@ Source={{ 'controller' if ((kuma_controller is defined) and (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined)) else 'vm' if (kuma_vm.stdout|default('')|trim|length>0) else 'n/a' }}; length={{ (kuma_home_html | default('')) | length }}; contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }} + when: DEBUG == 1 # 🪵 Only print in debug mode - name: Kuma | Homepage unavailable (after retries) ansible.builtin.debug: msg: "Kuma web není dostupná ani po pokusech." - when: kuma_home_html is not defined + when: kuma_home_html is not defined and DEBUG == 1 # Optional detailed dump (short excerpt only) - name: Kuma | HTML excerpt (debug) ansible.builtin.debug: msg: "{{ (kuma_home_html | default(''))[:500] }}" - when: kuma_home_html is defined + when: kuma_home_html is defined and DEBUG == 1 \ No newline at end of file