--- - name: Nextcloud maintenance (cron, app updates, repair, status, health check) hosts: nextcloud_host gather_facts: false vars: nextcloud_container: nextcloud tasks: - name: Ensure docker CLI is available ansible.builtin.command: argv: ["/usr/bin/env", "bash", "-lc", "command -v docker"] changed_when: false failed_when: result.rc != 0 register: result # English: Hard fail if docker is not present. - name: Verify Nextcloud container is running ansible.builtin.command: argv: ["docker", "ps", "--format", "{{.Names}}"] changed_when: false register: docker_ps # English: List running containers by name. - name: Fail if '{{ nextcloud_container }}' is not running ansible.builtin.fail: msg: "Container '{{ nextcloud_container }}' is not running on target host." when: nextcloud_container not in docker_ps.stdout_lines # English: Avoid obscure 'docker exec' errors later. - name: Run Nextcloud maintenance pipeline block: - name: 1) Run cron.php ansible.builtin.command: argv: - docker - exec - -u - www-data - "{{ nextcloud_container }}" - php - -f - /var/www/html/cron.php register: cron_run - name: 2) Update all apps ansible.builtin.command: argv: - docker - exec - -u - www-data - "{{ nextcloud_container }}" - php - occ - app:update - --all register: apps_update - name: 3) Run maintenance:repair (include expensive) ansible.builtin.command: argv: - docker - exec - -u - www-data - "{{ nextcloud_container }}" - php - occ - maintenance:repair - --include-expensive register: repair_run - name: 4) Show occ status ansible.builtin.command: argv: - docker - exec - -u - www-data - "{{ nextcloud_container }}" - php - occ - status register: occ_status changed_when: false - name: 5) Run stack health script ansible.builtin.command: argv: ["/data/compose/nextcloud/stack-health.sh"] register: health # English: If your script returns non-zero, the play will fail (desired in CI). always: - name: Print outputs from maintenance steps ansible.builtin.debug: msg: - "cron.php stdout: {{ cron_run.stdout | default('') }}" - "cron.php stderr: {{ cron_run.stderr | default('') }}" - "app:update stdout: {{ apps_update.stdout | default('') }}" - "app:update stderr: {{ apps_update.stderr | default('') }}" - "repair stdout: {{ repair_run.stdout | default('') }}" - "repair stderr: {{ repair_run.stderr | default('') }}" - "occ status:\n{{ occ_status.stdout | default('') }}" - "health stdout:\n{{ health.stdout | default('') }}"