Update playbooks/nextcloud-upgrade.yml
This commit is contained in:
@@ -1,28 +1,24 @@
|
|||||||
- name: Resilient & Environment-Aware Nextcloud Upgrade (Standalone)
|
- name: Fast-Track Nextcloud Upgrade (Skip Discovery)
|
||||||
hosts: all
|
hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# ⚠️ REQUIRED USER VARIABLES (Set by you)
|
# ⚠️ REQUIRED USER VARIABLES (TRUSTED)
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# 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 path (Confirmed or set to standard)
|
|
||||||
php_cli_path: /usr/bin/php
|
php_cli_path: /usr/bin/php
|
||||||
|
|
||||||
# 3. The service name for your webserver or PHP-FPM (Set to standard)
|
|
||||||
web_service_name: httpd
|
web_service_name: httpd
|
||||||
|
|
||||||
|
# User confirmed by 'ls -ld' output (e.g., apache, www-data, etc.)
|
||||||
|
nc_web_user: apache
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# INTERNAL PLAYBOOK VARIABLES
|
# INTERNAL PLAYBOOK VARIABLES
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# Environment for all occ commands
|
|
||||||
occ_env:
|
occ_env:
|
||||||
TMPDIR: /tmp
|
TMPDIR: /tmp
|
||||||
|
|
||||||
# Core apps to NOT disable during upgrade
|
|
||||||
core_apps:
|
core_apps:
|
||||||
- activity
|
- activity
|
||||||
- twofactor_nextcloud_notification
|
- twofactor_nextcloud_notification
|
||||||
@@ -45,71 +41,31 @@
|
|||||||
debug:
|
debug:
|
||||||
msg: "⚠️ CRITICAL: Ensure you have valid DB + data directory backups BEFORE PROCEEDING!"
|
msg: "⚠️ CRITICAL: Ensure you have valid DB + data directory backups BEFORE PROCEEDING!"
|
||||||
|
|
||||||
- name: Pause playbook for 10 seconds to allow backup cancellation
|
- name: Pause playbook for 3 seconds to allow backup cancellation
|
||||||
pause:
|
pause:
|
||||||
seconds: 10
|
seconds: 3
|
||||||
prompt: "Press Ctrl+C and then 'A' to abort if you do not have backups."
|
prompt: "Press Ctrl+C and then 'A' to abort if you do not have backups."
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# 🛡️ STAGE 1: PREFLIGHT CHECKS & FACT GATHERING
|
# 🚀 STAGE 1: VERSION CHECK
|
||||||
|
# (Discovery steps have been skipped, directly checking status)
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
- name: 1.1 - Validate 'nextcloud_dir'
|
- name: 1.1 - Get current NC status (and check if installed)
|
||||||
stat:
|
|
||||||
path: "{{ nextcloud_dir }}/config/config.php"
|
|
||||||
register: config_stat
|
|
||||||
|
|
||||||
- name: 1.2 - Fail if 'config.php' not found
|
|
||||||
fail:
|
|
||||||
msg: |
|
|
||||||
'config.php' not found at '{{ nextcloud_dir }}/config/config.php'.
|
|
||||||
Please correct the 'nextcloud_dir' variable in the playbook.
|
|
||||||
when: not config_stat.stat.exists
|
|
||||||
|
|
||||||
- name: 1.3 - 🧠 DISCOVER 'nc_web_user' from 'config.php' owner
|
|
||||||
set_fact:
|
|
||||||
nc_web_user: "{{ config_stat.stat.owner }}"
|
|
||||||
|
|
||||||
- name: 1.4 - Display discovered file owner
|
|
||||||
debug:
|
|
||||||
msg: "Discovered Nextcloud web user: {{ nc_web_user }}"
|
|
||||||
|
|
||||||
- name: 1.5 - Validate 'php_cli_path'
|
|
||||||
stat:
|
|
||||||
path: "{{ php_cli_path }}"
|
|
||||||
register: php_stat
|
|
||||||
|
|
||||||
- name: 1.6 - Fail if 'php_cli_path' is not an executable file
|
|
||||||
fail:
|
|
||||||
msg: |
|
|
||||||
'php_cli_path' ('{{ php_cli_path }}') does not exist or is not executable.
|
|
||||||
Please correct the 'php_cli_path' variable.
|
|
||||||
when: not php_stat.stat.exists or not php_stat.stat.isexe
|
|
||||||
|
|
||||||
- name: 1.7 - Validate 'web_service_name'
|
|
||||||
service_facts:
|
|
||||||
|
|
||||||
- name: 1.8 - Fail if 'web_service_name' is not a known service
|
|
||||||
fail:
|
|
||||||
msg: |
|
|
||||||
'web_service_name' ('{{ web_service_name }}') is not a valid service on this host.
|
|
||||||
Please correct the 'web_service_name' variable.
|
|
||||||
when: "web_service_name not in ansible_facts.services"
|
|
||||||
|
|
||||||
- name: 1.9 - Get current NC status (and check if installed)
|
|
||||||
command: "{{ php_cli_path }} occ status"
|
command: "{{ php_cli_path }} occ status"
|
||||||
args:
|
args:
|
||||||
chdir: "{{ nextcloud_dir }}"
|
chdir: "{{ nextcloud_dir }}"
|
||||||
become_user: "{{ nc_web_user }}"
|
become_user: "{{ nc_web_user }}"
|
||||||
register: occ_status
|
register: occ_status
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
# This still fails if Nextcloud is not installed or paths are severely wrong
|
||||||
failed_when: "'installed: true' not in occ_status.stdout"
|
failed_when: "'installed: true' not in occ_status.stdout"
|
||||||
|
|
||||||
- name: 1.10 - Parse and show current version
|
- name: 1.2 - Parse and show current version
|
||||||
set_fact:
|
set_fact:
|
||||||
current_version: "{{ occ_status.stdout | regex_search('versionstring: (.*)', '\\1') | first | default('unknown') }}"
|
current_version: "{{ occ_status.stdout | regex_search('versionstring: (.*)', '\\1') | first | default('unknown') }}"
|
||||||
when: occ_status.stdout is defined
|
when: occ_status.stdout is defined
|
||||||
|
|
||||||
- name: 1.11 - Show current version
|
- name: 1.3 - Show current version
|
||||||
debug:
|
debug:
|
||||||
msg: "Current Nextcloud version: {{ current_version }}"
|
msg: "Current Nextcloud version: {{ current_version }}"
|
||||||
|
|
||||||
@@ -175,7 +131,6 @@
|
|||||||
chdir: "{{ nextcloud_dir }}"
|
chdir: "{{ nextcloud_dir }}"
|
||||||
become_user: "{{ nc_web_user }}"
|
become_user: "{{ nc_web_user }}"
|
||||||
environment: "{{ occ_env }}"
|
environment: "{{ occ_env }}"
|
||||||
# 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 }}"
|
||||||
@@ -228,7 +183,7 @@
|
|||||||
msg: "Nextcloud successfully upgraded!"
|
msg: "Nextcloud successfully upgraded!"
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# 🆘 STAGE 4: RESCUE BLOCK (This ONLY runs if STAGE 3 fails)
|
# 🆘 STAGE 4: RESCUE BLOCK
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
rescue:
|
rescue:
|
||||||
|
|
||||||
@@ -241,7 +196,7 @@
|
|||||||
The server is being LEFT IN MAINTENANCE MODE for manual inspection.
|
The server is being LEFT IN MAINTENANCE MODE for manual inspection.
|
||||||
|
|
||||||
Host: {{ inventory_hostname }}
|
Host: {{ inventory_hostname }}
|
||||||
Discovered Web User: {{ nc_web_user }}
|
Web User: {{ nc_web_user }}
|
||||||
|
|
||||||
Please SSH to the host and check logs to fix manually.
|
Please SSH to the host and check logs to fix manually.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user