# nextcloud/check_stack_nextcloud.yml - name: Run Nextcloud maintenance on VM via Proxmox hosts: proxmox_nextcloud gather_facts: false become: true become_user: root become_method: sudo vars: vm_password: "{{ lookup('ansible.builtin.env', 'vm_pass') }}" vm_use_sudo: "{{ use_sudo | default(false) | bool }}" 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 - >- set -o pipefail; timeout 180s bash -x /data/compose/nextcloud/stack-health.sh 0 - vm_user is defined - vm_user | string | trim | length > 0 - vm_password | length > 0 fail_msg: >- Missing vm_ip, vm_user or vm_pass. Check the attached Semaphore Variable Group. quiet: true no_log: true tasks: - name: Ensure sshpass is installed ansible.builtin.apt: name: sshpass state: present update_cache: true - name: Run Nextcloud commands on VM ansible.builtin.command: argv: - sshpass - -e - ssh - -o - StrictHostKeyChecking=no - -o - UserKnownHostsFile=/dev/null - -o - ConnectTimeout=15 - -o - ServerAliveInterval=10 - -o - ServerAliveCountMax=3 - "{{ vm_user }}@{{ vm_ip }}" - >- {{ ('sudo -n bash -lc ' ~ (item | quote)) if vm_use_sudo else ('bash -lc ' ~ (item | quote)) }} environment: SSHPASS: "{{ vm_password }}" loop: "{{ vm_commands }}" loop_control: label: "{{ item }}" register: vm_cmds changed_when: false failed_when: false no_log: true - name: Show outputs for each command ansible.builtin.debug: msg: | CMD: {{ item.item }} RC: {{ item.rc }} STDOUT: {{ item.stdout | default('') | trim }} STDERR: {{ item.stderr | default('') | trim }} loop: "{{ vm_cmds.results }}" loop_control: label: "{{ item.item }}" - name: Fail play if any command failed ansible.builtin.assert: that: - item.rc == 0 fail_msg: | Command failed on VM: {{ item.item }} RC: {{ item.rc }} STDERR: {{ item.stderr | default('') | trim }} quiet: true loop: "{{ vm_cmds.results }}" loop_control: label: "{{ item.item }}"