3
0
forked from jakub/ansible

Refactor update_collabora.yml: add comprehensive maintenance and update commands for Nextcloud and Collabora with error handling

This commit is contained in:
fencl
2025-10-05 09:22:42 +02:00
parent 1a8690529c
commit b7f6d38a32

View File

@@ -0,0 +1,154 @@
# """
# Run the command and check the response.
#
# :parameter command: The command to be executed.
# :parameter add_command: Whether to include the command in the database values.
# :parameter add_response: Whether to include the response in the database values.
# :parameter measurement: The measurement index for the command.
# :parameter measure_retries: The number of retries for measurement in case of failure.
# :parameter check_port: Whether to check the port before sending the command.
# :parameter response_equals: The expected response string to compare against.
# :parameter response_length: The expected length or format of the response.
# :parameter send_skipped: Whether to mark the test as skipped without execution.
# :parameter no_response: Whether to expect no response from the command.
# :parameter expect_patch_id_decimal: The expected patch ID in decimal format for validation.
# :parameter response_equals_match: The expected response string to match against.
# :return: RunResultType
# """
- name: Run Nextcloud maintenance on VM via Proxmox
hosts: proxmox
gather_facts: false
become: true
become_user: root
become_method: sudo
vars:
vm_ip: "{{ lookup('env', 'VM_IP') }}"
vm_user: "{{ lookup('env', 'VM_USER') }}"
vm_pass: "{{ lookup('env', 'VM_PASS') }}"
# Flip to true if Docker needs sudo on the VM
use_sudo: false
# ---------- Collabora settings ----------
collabora_project: "nextcloud-collabora"
collabora_compose_file: "/data/compose/nextcloud/collabora-only.yml"
# ---------- Nextcloud commands ----------
vm_commands:
- "docker exec -u www-data nextcloud php -f /var/www/html/cron.php"
- "docker exec -u www-data nextcloud php occ app:update --all"
- "docker exec -u www-data nextcloud php occ maintenance:repair --include-expensive"
- "docker exec -u www-data nextcloud php occ status"
# English comments: run health script non-interactively with a timeout and xtrace for debugging
- "set -o pipefail; timeout 180s bash -x /data/compose/nextcloud/stack-health.sh </dev/null"
# ---------- Collabora update commands ----------
collabora_commands:
# English comments: pre-pull latest base image (optional but keeps cache warm)
- "timeout 600s docker pull collabora/code:latest"
# English comments: pull service image defined in compose file
- "timeout 600s docker compose -p {{ collabora_project }} -f {{ collabora_compose_file }} pull collabora"
# English comments: recreate only the 'collabora' service without touching dependencies
- "timeout 600s docker compose -p {{ collabora_project }} -f {{ collabora_compose_file }} up -d --no-deps --force-recreate collabora"
tasks:
- name: Ensure sshpass is installed (for password-based SSH) # English comments
ansible.builtin.apt:
name: sshpass
state: present
update_cache: yes
- name: Preflight | Ensure Collabora compose file exists on VM # English comments
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 '') }}test -f '{{ collabora_compose_file }}'"
register: collab_preflight
changed_when: false
failed_when: collab_preflight.rc != 0
- name: Run Nextcloud commands on VM (via SSH, argv, no line breaks)
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: "{{ vm_commands }}"
register: vm_cmds
changed_when: false
- name: Show outputs for each Nextcloud command
ansible.builtin.debug:
msg: |
CMD: {{ item.item }}
RC: {{ item.rc }}
STDOUT:
{{ (item.stdout | default('')).strip() }}
STDERR:
{{ (item.stderr | default('')).strip() }}
loop: "{{ vm_cmds.results }}"
- name: Fail play if any Nextcloud command failed
ansible.builtin.assert:
that: "item.rc == 0"
fail_msg: "Command failed on VM: {{ item.item }} (rc={{ item.rc }}) {{ ' -- likely timeout' if item.rc == 124 else '' }}"
success_msg: "All Nextcloud commands succeeded."
loop: "{{ vm_cmds.results }}"
- name: Update Collabora on VM (via SSH, argv, no line breaks)
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: "{{ collabora_commands }}"
register: collab_cmds
changed_when: false
- name: Show outputs for each Collabora command
ansible.builtin.debug:
msg: |
CMD: {{ item.item }}
RC: {{ item.rc }}
STDOUT:
{{ (item.stdout | default('')).strip() }}
STDERR:
{{ (item.stderr | default('')).strip() }}
loop: "{{ collab_cmds.results }}"
- name: Fail play if any Collabora command failed
ansible.builtin.assert:
that: "item.rc == 0"
fail_msg: "Collabora update failed on VM: {{ item.item }} (rc={{ item.rc }}) {{ ' -- likely timeout' if item.rc == 124 else '' }}"
success_msg: "Collabora updated successfully."
loop: "{{ collab_cmds.results }}"