Update playbooks/nextcloud-upgrade.yml

This commit is contained in:
2025-11-14 13:22:35 +00:00
parent e47ab0e538
commit 8b7fe77677
+27 -31
View File
@@ -1,27 +1,23 @@
- name: Resilient & Environment-Aware Nextcloud Upgrade - name: Resilient & Environment-Aware Nextcloud Upgrade (Standalone)
hosts: all hosts: all
become: yes become: yes
# ----------------------------------------------------------------------
# ⚠️ REQUIRED USER VARIABLES
# ----------------------------------------------------------------------
# YOU MUST EDIT THESE 3 VARIABLES TO MATCH YOUR SERVER
vars: vars:
# 1. The full path to your Nextcloud installation # ----------------------------------------------------------------------
# ⚠️ REQUIRED USER VARIABLES (Set by you)
# ----------------------------------------------------------------------
# 1. The root path to your Nextcloud installation (Confirmed)
nextcloud_dir: /var/www/nextcloud nextcloud_dir: /var/www/nextcloud
# 2. The *exact* PHP CLI binary your Nextcloud uses # 2. The *exact* PHP CLI binary path (Confirmed or set to standard)
# (e.g., /usr/bin/php, /usr/bin/php8.1, /opt/remi/php81/root/bin/php)
php_cli_path: /usr/bin/php php_cli_path: /usr/bin/php
# 3. The service name for your webserver or PHP-FPM # 3. The service name for your webserver or PHP-FPM (Set to standard)
# (e.g., httpd, apache2, nginx, php8.1-fpm)
web_service_name: httpd web_service_name: httpd
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# INTERNAL PLAYBOOK VARIABLES # INTERNAL PLAYBOOK VARIABLES
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
vars:
# Environment for all occ commands # Environment for all occ commands
occ_env: occ_env:
TMPDIR: /tmp TMPDIR: /tmp
@@ -45,6 +41,15 @@
tasks: tasks:
- name: Reminder - ensure backups exist
debug:
msg: "⚠️ CRITICAL: Ensure you have valid DB + data directory backups BEFORE PROCEEDING!"
- name: Pause playbook for 10 seconds to allow backup cancellation
pause:
seconds: 10
prompt: "Press Ctrl+C and then 'A' to abort if you do not have backups."
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 🛡️ STAGE 1: PREFLIGHT CHECKS & FACT GATHERING # 🛡️ STAGE 1: PREFLIGHT CHECKS & FACT GATHERING
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
@@ -111,16 +116,7 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 🔄 STAGE 2: PRE-UPGRADE PREPARATION # 🔄 STAGE 2: PRE-UPGRADE PREPARATION
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
- name: 2.1 - Backup Reminder - name: 2.1 - Get list of installed apps
debug:
msg: "⚠️ CRITICAL: Ensure you have valid DB + data directory backups BEFORE PROCEEDING!"
- name: 2.2 - Pause playbook for 10 seconds to allow cancellation
pause:
seconds: 10
prompt: "Press Ctrl+C and then 'A' to abort if you do not have backups."
- name: 2.3 - Get list of installed apps
command: "{{ php_cli_path }} occ app:list" command: "{{ php_cli_path }} occ app:list"
args: args:
chdir: "{{ nextcloud_dir }}" chdir: "{{ nextcloud_dir }}"
@@ -128,7 +124,7 @@
register: app_list register: app_list
changed_when: false changed_when: false
- name: 2.4 - Disable all non-core 3rd party apps - name: 2.2 - Disable all non-core 3rd party apps
command: "{{ php_cli_path }} occ app:disable {{ item }}" command: "{{ php_cli_path }} occ app:disable {{ item }}"
args: args:
chdir: "{{ nextcloud_dir }}" chdir: "{{ nextcloud_dir }}"
@@ -137,9 +133,9 @@
loop: "{{ app_list.stdout_lines | select('match', '^[ ]*-[ ](.*):[ ]enabled$') | map('regex_replace', '^[ ]*-[ ](.*):[ ]enabled$', '\\1') | list }}" loop: "{{ app_list.stdout_lines | select('match', '^[ ]*-[ ](.*):[ ]enabled$') | map('regex_replace', '^[ ]*-[ ](.*):[ ]enabled$', '\\1') | list }}"
register: app_disable_result register: app_disable_result
when: item not in core_apps when: item not in core_apps
ignore_errors: yes # Don't fail if an app can't be disabled ignore_errors: yes
- name: 2.5 - Save list of successfully disabled apps - name: 2.3 - Save list of successfully disabled apps for re-enabling
set_fact: set_fact:
disabled_apps: "{{ app_disable_result.results | selectattr('changed', 'defined') | selectattr('changed') | map(attribute='item') | list }}" disabled_apps: "{{ app_disable_result.results | selectattr('changed', 'defined') | selectattr('changed') | map(attribute='item') | list }}"
when: app_disable_result is defined and app_disable_result.results is defined when: app_disable_result is defined and app_disable_result.results is defined
@@ -173,13 +169,13 @@
- updater_result.rc != 0 - updater_result.rc != 0
- "'Nextcloud is already latest version' not in updater_result.stdout" - "'Nextcloud is already latest version' not in updater_result.stdout"
- name: 3.3 - Run occ upgrade (This is the most critical step) - name: 3.3 - Run occ upgrade (Critical Database Step)
command: "{{ php_cli_path }} occ upgrade" command: "{{ php_cli_path }} occ upgrade"
args: args:
chdir: "{{ nextcloud_dir }}" chdir: "{{ nextcloud_dir }}"
become_user: "{{ nc_web_user }}" become_user: "{{ nc_web_user }}"
environment: "{{ occ_env }}" environment: "{{ occ_env }}"
# CRITICAL: Do NOT ignore errors here. If this fails, we must stop. # CRITICAL: This must fail if the upgrade fails.
- name: 3.4 - Run optional cleanup commands - name: 3.4 - Run optional cleanup commands
command: "{{ item }}" command: "{{ item }}"
@@ -190,7 +186,7 @@
loop: loop:
- "{{ php_cli_path }} occ db:add-missing-indices" - "{{ php_cli_path }} occ db:add-missing-indices"
- "{{ php_cli_path }} occ db:convert-filecache-bigint --no-interaction" - "{{ php_cli_path }} occ db:convert-filecache-bigint --no-interaction"
ignore_errors: yes # These are optional, so we ignore failures ignore_errors: yes
- name: 3.5 - Disable maintenance mode (SUCCESS) - name: 3.5 - Disable maintenance mode (SUCCESS)
command: "{{ php_cli_path }} occ maintenance:mode --off" command: "{{ php_cli_path }} occ maintenance:mode --off"
@@ -207,7 +203,7 @@
environment: "{{ occ_env }}" environment: "{{ occ_env }}"
loop: "{{ disabled_apps | default([]) }}" loop: "{{ disabled_apps | default([]) }}"
when: disabled_apps is defined and disabled_apps | length > 0 when: disabled_apps is defined and disabled_apps | length > 0
ignore_errors: yes # Don't let a single app fail the whole restart ignore_errors: yes
- name: 3.7 - Restart web service - name: 3.7 - Restart web service
service: service: