Update playbooks/nextcloud-upgrade.yml
This commit is contained in:
@@ -1,27 +1,23 @@
|
||||
- name: Resilient & Environment-Aware Nextcloud Upgrade
|
||||
- name: Resilient & Environment-Aware Nextcloud Upgrade (Standalone)
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# ⚠️ REQUIRED USER VARIABLES
|
||||
# ----------------------------------------------------------------------
|
||||
# YOU MUST EDIT THESE 3 VARIABLES TO MATCH YOUR SERVER
|
||||
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
|
||||
|
||||
# 2. The *exact* PHP CLI binary your Nextcloud uses
|
||||
# (e.g., /usr/bin/php, /usr/bin/php8.1, /opt/remi/php81/root/bin/php)
|
||||
# 2. The *exact* PHP CLI binary path (Confirmed or set to standard)
|
||||
php_cli_path: /usr/bin/php
|
||||
|
||||
# 3. The service name for your webserver or PHP-FPM
|
||||
# (e.g., httpd, apache2, nginx, php8.1-fpm)
|
||||
# 3. The service name for your webserver or PHP-FPM (Set to standard)
|
||||
web_service_name: httpd
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# INTERNAL PLAYBOOK VARIABLES
|
||||
# ----------------------------------------------------------------------
|
||||
vars:
|
||||
# ----------------------------------------------------------------------
|
||||
# INTERNAL PLAYBOOK VARIABLES
|
||||
# ----------------------------------------------------------------------
|
||||
# Environment for all occ commands
|
||||
occ_env:
|
||||
TMPDIR: /tmp
|
||||
@@ -45,6 +41,15 @@
|
||||
|
||||
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
|
||||
# ----------------------------------------------------------------------
|
||||
@@ -111,16 +116,7 @@
|
||||
# ----------------------------------------------------------------------
|
||||
# 🔄 STAGE 2: PRE-UPGRADE PREPARATION
|
||||
# ----------------------------------------------------------------------
|
||||
- name: 2.1 - Backup Reminder
|
||||
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
|
||||
- name: 2.1 - Get list of installed apps
|
||||
command: "{{ php_cli_path }} occ app:list"
|
||||
args:
|
||||
chdir: "{{ nextcloud_dir }}"
|
||||
@@ -128,7 +124,7 @@
|
||||
register: app_list
|
||||
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 }}"
|
||||
args:
|
||||
chdir: "{{ nextcloud_dir }}"
|
||||
@@ -137,9 +133,9 @@
|
||||
loop: "{{ app_list.stdout_lines | select('match', '^[ ]*-[ ](.*):[ ]enabled$') | map('regex_replace', '^[ ]*-[ ](.*):[ ]enabled$', '\\1') | list }}"
|
||||
register: app_disable_result
|
||||
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:
|
||||
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
|
||||
@@ -173,13 +169,13 @@
|
||||
- updater_result.rc != 0
|
||||
- "'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"
|
||||
args:
|
||||
chdir: "{{ nextcloud_dir }}"
|
||||
become_user: "{{ nc_web_user }}"
|
||||
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
|
||||
command: "{{ item }}"
|
||||
@@ -190,7 +186,7 @@
|
||||
loop:
|
||||
- "{{ php_cli_path }} occ db:add-missing-indices"
|
||||
- "{{ 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)
|
||||
command: "{{ php_cli_path }} occ maintenance:mode --off"
|
||||
@@ -207,7 +203,7 @@
|
||||
environment: "{{ occ_env }}"
|
||||
loop: "{{ disabled_apps | default([]) }}"
|
||||
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
|
||||
service:
|
||||
|
||||
Reference in New Issue
Block a user