forked from jakub/ansible
test3
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
become_method: sudo
|
become_method: sudo
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# Internal normalized variables
|
|
||||||
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
||||||
|
|
||||||
vm_commands:
|
vm_commands:
|
||||||
@@ -30,8 +29,8 @@
|
|||||||
|
|
||||||
- >-
|
- >-
|
||||||
set -o pipefail;
|
set -o pipefail;
|
||||||
timeout 180s bash -x
|
timeout 180s
|
||||||
/data/compose/nextcloud/stack-health.sh
|
bash -x /data/compose/nextcloud/stack-health.sh
|
||||||
</dev/null
|
</dev/null
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
@@ -46,7 +45,7 @@
|
|||||||
- vm_pass | string | length > 0
|
- vm_pass | string | length > 0
|
||||||
fail_msg: >-
|
fail_msg: >-
|
||||||
Missing vm_ip, vm_user or vm_pass.
|
Missing vm_ip, vm_user or vm_pass.
|
||||||
Configure these variables in the attached Semaphore Variable Group.
|
Configure them in the attached Semaphore Variable Group.
|
||||||
quiet: true
|
quiet: true
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
@@ -69,13 +68,17 @@
|
|||||||
- UserKnownHostsFile=/dev/null
|
- UserKnownHostsFile=/dev/null
|
||||||
- -o
|
- -o
|
||||||
- ConnectTimeout=15
|
- ConnectTimeout=15
|
||||||
|
- -o
|
||||||
|
- ServerAliveInterval=10
|
||||||
|
- -o
|
||||||
|
- ServerAliveCountMax=3
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
- "{{ vm_user }}@{{ vm_ip }}"
|
||||||
- >-
|
- >-
|
||||||
{{
|
{{
|
||||||
('sudo -n bash -lc ' + (item | quote))
|
('sudo -n bash -lc ' ~ (item | quote))
|
||||||
if vm_use_sudo
|
if vm_use_sudo
|
||||||
else
|
else
|
||||||
('bash -lc ' + (item | quote))
|
('bash -lc ' ~ (item | quote))
|
||||||
}}
|
}}
|
||||||
environment:
|
environment:
|
||||||
SSHPASS: "{{ vm_pass }}"
|
SSHPASS: "{{ vm_pass }}"
|
||||||
@@ -91,10 +94,12 @@
|
|||||||
msg: |
|
msg: |
|
||||||
CMD: {{ item.item }}
|
CMD: {{ item.item }}
|
||||||
RC: {{ item.rc }}
|
RC: {{ item.rc }}
|
||||||
|
|
||||||
STDOUT:
|
STDOUT:
|
||||||
{{ (item.stdout | default('') | trim) }}
|
{{ item.stdout | default('') | trim }}
|
||||||
|
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ (item.stderr | default('') | trim) }}
|
{{ item.stderr | default('') | trim }}
|
||||||
loop: "{{ vm_cmds.results }}"
|
loop: "{{ vm_cmds.results }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.item }}"
|
label: "{{ item.item }}"
|
||||||
@@ -103,9 +108,9 @@
|
|||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- item.rc == 0
|
- item.rc == 0
|
||||||
fail_msg: >-
|
fail_msg: |
|
||||||
Command failed on VM: {{ item.item }}
|
Command failed on VM: {{ item.item }}
|
||||||
(rc={{ item.rc }})
|
RC: {{ item.rc }}
|
||||||
|
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ item.stderr | default('') | trim }}
|
{{ item.stderr | default('') | trim }}
|
||||||
|
|||||||
+265
-303
@@ -1,4 +1,4 @@
|
|||||||
# nextcloud/update_nextcloud.yml
|
# nextcloud/update_nextcloud_v2.yml
|
||||||
|
|
||||||
- name: Update Nextcloud on VM via Proxmox
|
- name: Update Nextcloud on VM via Proxmox
|
||||||
hosts: proxmox_nextcloud
|
hosts: proxmox_nextcloud
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
become_method: sudo
|
become_method: sudo
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# Internal normalized variables
|
# Normalized values from Semaphore Variable Group
|
||||||
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
||||||
debug_level: "{{ DEBUG | default(0) | int }}"
|
debug_level: "{{ DEBUG | default(0) | int }}"
|
||||||
retry_count: "{{ RETRIES | default(25) | int }}"
|
retry_count: "{{ RETRIES | default(25) | int }}"
|
||||||
@@ -21,51 +21,64 @@
|
|||||||
nextcloud_container: "nextcloud"
|
nextcloud_container: "nextcloud"
|
||||||
nextcloud_db_container: "nextcloud-db"
|
nextcloud_db_container: "nextcloud-db"
|
||||||
|
|
||||||
backup_dir: >-
|
|
||||||
/data/compose/nextcloud/backup-{{
|
|
||||||
lookup('pipe', 'date +%F-%H%M%S')
|
|
||||||
}}
|
|
||||||
|
|
||||||
nextcloud_base_url: "https://cloud.martinfencl.eu"
|
nextcloud_base_url: "https://cloud.martinfencl.eu"
|
||||||
nextcloud_status_url: "{{ nextcloud_base_url }}/status.php"
|
nextcloud_status_url: "{{ nextcloud_base_url }}/status.php"
|
||||||
|
|
||||||
|
backup_timestamp: "{{ lookup('pipe', 'date +%F-%H%M%S') }}"
|
||||||
|
backup_dir: "/data/compose/nextcloud/backup-{{ backup_timestamp }}"
|
||||||
|
|
||||||
docker_prefix: >-
|
docker_prefix: >-
|
||||||
unalias docker 2>/dev/null || true;
|
unalias docker 2>/dev/null || true;
|
||||||
export DOCKER_CLI_HINTS=0;
|
export DOCKER_CLI_HINTS=0;
|
||||||
command docker
|
command docker
|
||||||
|
|
||||||
# Backup commands executed inside the Nextcloud VM
|
nextcloud_version_command: >-
|
||||||
|
docker exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
|
php occ -V
|
||||||
|
|
||||||
|
nextcloud_maintenance_off_command: >-
|
||||||
|
docker exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
|
php occ maintenance:mode --off
|
||||||
|
|
||||||
|
# Commands executed before the container update
|
||||||
nextcloud_backup_commands:
|
nextcloud_backup_commands:
|
||||||
- >-
|
- >-
|
||||||
mkdir -p {{ backup_dir | quote }}
|
mkdir -p {{ backup_dir | quote }}
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec -u www-data {{ nextcloud_container }}
|
exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
php occ maintenance:mode --on
|
php occ maintenance:mode --on
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec {{ nextcloud_container }}
|
exec
|
||||||
|
{{ nextcloud_container }}
|
||||||
sh -c
|
sh -c
|
||||||
'tar czf /tmp/nextcloud_conf.tgz
|
'tar czf /tmp/nextcloud_conf.tgz
|
||||||
-C /var/www/html config custom_apps'
|
-C /var/www/html
|
||||||
|
config custom_apps'
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
cp
|
cp
|
||||||
{{ nextcloud_container }}:/tmp/nextcloud_conf.tgz
|
{{ nextcloud_container }}:/tmp/nextcloud_conf.tgz
|
||||||
{{ (backup_dir + '/nextcloud_conf.tgz') | quote }}
|
{{ (backup_dir ~ '/nextcloud_conf.tgz') | quote }}
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec {{ nextcloud_container }}
|
exec
|
||||||
|
{{ nextcloud_container }}
|
||||||
rm -f /tmp/nextcloud_conf.tgz
|
rm -f /tmp/nextcloud_conf.tgz
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
set -o pipefail;
|
set -o pipefail;
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec {{ nextcloud_db_container }}
|
exec
|
||||||
|
{{ nextcloud_db_container }}
|
||||||
sh -c
|
sh -c
|
||||||
'if command -v mariadb-dump >/dev/null 2>&1; then
|
'if command -v mariadb-dump >/dev/null 2>&1; then
|
||||||
exec mariadb-dump
|
exec mariadb-dump
|
||||||
@@ -78,22 +91,25 @@
|
|||||||
-p"$MYSQL_PASSWORD"
|
-p"$MYSQL_PASSWORD"
|
||||||
"$MYSQL_DATABASE";
|
"$MYSQL_DATABASE";
|
||||||
fi'
|
fi'
|
||||||
> {{ (backup_dir + '/db.sql') | quote }}
|
> {{ (backup_dir ~ '/db.sql') | quote }}
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
test -s {{ (backup_dir + '/nextcloud_conf.tgz') | quote }}
|
test -s
|
||||||
|
{{ (backup_dir ~ '/nextcloud_conf.tgz') | quote }}
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
test -s {{ (backup_dir + '/db.sql') | quote }}
|
test -s
|
||||||
|
{{ (backup_dir ~ '/db.sql') | quote }}
|
||||||
|
|
||||||
# Upgrade commands executed while maintenance mode remains enabled
|
# Commands executed while maintenance mode is enabled
|
||||||
nextcloud_upgrade_commands:
|
nextcloud_upgrade_commands:
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
compose
|
compose
|
||||||
-p {{ nextcloud_project | quote }}
|
-p {{ nextcloud_project | quote }}
|
||||||
-f {{ nextcloud_compose_file | quote }}
|
-f {{ nextcloud_compose_file | quote }}
|
||||||
pull {{ nextcloud_service | quote }}
|
pull
|
||||||
|
{{ nextcloud_service | quote }}
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
@@ -108,29 +124,44 @@
|
|||||||
- >-
|
- >-
|
||||||
timeout 180s bash -c
|
timeout 180s bash -c
|
||||||
'until docker inspect
|
'until docker inspect
|
||||||
--format "{{ '{{' }}.State.Running{{ '}}' }}"
|
--format="{{ '{{' }}.State.Running{{ '}}' }}"
|
||||||
{{ nextcloud_container | quote }}
|
{{ nextcloud_container | quote }}
|
||||||
2>/dev/null | grep -qx true;
|
2>/dev/null | grep -qx true;
|
||||||
do sleep 3; done'
|
do
|
||||||
|
sleep 3;
|
||||||
|
done'
|
||||||
|
|
||||||
|
- >-
|
||||||
|
timeout 180s bash -c
|
||||||
|
'until docker exec -u www-data
|
||||||
|
{{ nextcloud_container | quote }}
|
||||||
|
php occ status >/dev/null 2>&1;
|
||||||
|
do
|
||||||
|
sleep 3;
|
||||||
|
done'
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec -u www-data {{ nextcloud_container }}
|
exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
php occ upgrade
|
php occ upgrade
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec -u www-data {{ nextcloud_container }}
|
exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
php occ app:update --all
|
php occ app:update --all
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec -u www-data {{ nextcloud_container }}
|
exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
php occ maintenance:repair --include-expensive
|
php occ maintenance:repair --include-expensive
|
||||||
|
|
||||||
- >-
|
- >-
|
||||||
{{ docker_prefix }}
|
{{ docker_prefix }}
|
||||||
exec -u www-data {{ nextcloud_container }}
|
exec -u www-data
|
||||||
|
{{ nextcloud_container }}
|
||||||
php occ status
|
php occ status
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
@@ -143,9 +174,10 @@
|
|||||||
- vm_user | string | trim | length > 0
|
- vm_user | string | trim | length > 0
|
||||||
- vm_pass is defined
|
- vm_pass is defined
|
||||||
- vm_pass | string | length > 0
|
- vm_pass | string | length > 0
|
||||||
|
- retry_count | int > 0
|
||||||
fail_msg: >-
|
fail_msg: >-
|
||||||
Missing vm_ip, vm_user or vm_pass.
|
Missing or invalid vm_ip, vm_user, vm_pass or RETRIES.
|
||||||
Configure these variables in the attached Semaphore Variable Group.
|
Configure them in the attached Semaphore Variable Group.
|
||||||
quiet: true
|
quiet: true
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
@@ -171,22 +203,12 @@
|
|||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
- "{{ vm_user }}@{{ vm_ip }}"
|
||||||
- >-
|
- >-
|
||||||
{{
|
{{
|
||||||
(
|
('sudo -n bash -lc ' ~
|
||||||
'sudo -n bash -lc ' +
|
(nextcloud_version_command | quote))
|
||||||
(
|
|
||||||
'docker exec -u www-data nextcloud php occ -V'
|
|
||||||
| quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if vm_use_sudo
|
if vm_use_sudo
|
||||||
else
|
else
|
||||||
(
|
('bash -lc ' ~
|
||||||
'bash -lc ' +
|
(nextcloud_version_command | quote))
|
||||||
(
|
|
||||||
'docker exec -u www-data nextcloud php occ -V'
|
|
||||||
| quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
environment:
|
environment:
|
||||||
SSHPASS: "{{ vm_pass }}"
|
SSHPASS: "{{ vm_pass }}"
|
||||||
@@ -197,303 +219,243 @@
|
|||||||
|
|
||||||
- name: Nextcloud | Print current version
|
- name: Nextcloud | Print current version
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "{{ nc_version_before.stdout | default('Version unavailable') }}"
|
msg: >-
|
||||||
|
{{
|
||||||
|
nc_version_before.stdout
|
||||||
|
| default('Nextcloud version is unavailable')
|
||||||
|
| trim
|
||||||
|
}}
|
||||||
when: debug_level == 1
|
when: debug_level == 1
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
- name: Nextcloud | Run backup and upgrade
|
||||||
# Backup
|
block:
|
||||||
# -------------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
|
# Backup
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
|
||||||
- name: Nextcloud | Run backup commands on VM
|
- name: Nextcloud | Run backup commands on VM
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
- -e
|
- -e
|
||||||
- ssh
|
- ssh
|
||||||
- -o
|
- -o
|
||||||
- StrictHostKeyChecking=no
|
- StrictHostKeyChecking=no
|
||||||
- -o
|
- -o
|
||||||
- UserKnownHostsFile=/dev/null
|
- UserKnownHostsFile=/dev/null
|
||||||
- -o
|
- -o
|
||||||
- ConnectTimeout=15
|
- ConnectTimeout=15
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
- -o
|
||||||
- >-
|
- ServerAliveInterval=10
|
||||||
{{
|
- -o
|
||||||
('sudo -n bash -lc ' + (item | quote))
|
- ServerAliveCountMax=3
|
||||||
if vm_use_sudo
|
- "{{ vm_user }}@{{ vm_ip }}"
|
||||||
else
|
- >-
|
||||||
('bash -lc ' + (item | quote))
|
{{
|
||||||
}}
|
('sudo -n bash -lc ' ~ (item | quote))
|
||||||
environment:
|
if vm_use_sudo
|
||||||
SSHPASS: "{{ vm_pass }}"
|
else
|
||||||
loop: "{{ nextcloud_backup_commands }}"
|
('bash -lc ' ~ (item | quote))
|
||||||
loop_control:
|
}}
|
||||||
index_var: backup_index
|
environment:
|
||||||
label: "backup-cmd-{{ backup_index }}"
|
SSHPASS: "{{ vm_pass }}"
|
||||||
register: nc_backup_cmds
|
loop: "{{ nextcloud_backup_commands }}"
|
||||||
changed_when: false
|
loop_control:
|
||||||
failed_when: false
|
index_var: backup_index
|
||||||
|
label: "backup-cmd-{{ backup_index }}"
|
||||||
|
register: nc_backup_cmds
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
- name: Nextcloud | Show backup command outputs
|
- name: Nextcloud | Show backup command outputs
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
CMD: {{ item.item }}
|
CMD: {{ item.item }}
|
||||||
RC: {{ item.rc }}
|
RC: {{ item.rc }}
|
||||||
STDOUT:
|
|
||||||
{{ item.stdout | default('') | trim }}
|
|
||||||
STDERR:
|
|
||||||
{{ item.stderr | default('') | trim }}
|
|
||||||
loop: "{{ nc_backup_cmds.results }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: backup_debug_index
|
|
||||||
label: "backup-cmd-{{ backup_debug_index }}"
|
|
||||||
when: debug_level == 1
|
|
||||||
|
|
||||||
- name: Nextcloud | Fail if any backup command failed
|
STDOUT:
|
||||||
ansible.builtin.assert:
|
{{ item.stdout | default('') | trim }}
|
||||||
that:
|
|
||||||
- item.rc == 0
|
|
||||||
fail_msg: >-
|
|
||||||
Nextcloud backup command failed:
|
|
||||||
{{ item.item }}
|
|
||||||
(rc={{ item.rc }})
|
|
||||||
|
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ item.stderr | default('') | trim }}
|
{{ item.stderr | default('') | trim }}
|
||||||
quiet: true
|
loop: "{{ nc_backup_cmds.results }}"
|
||||||
loop: "{{ nc_backup_cmds.results }}"
|
loop_control:
|
||||||
loop_control:
|
index_var: backup_debug_index
|
||||||
index_var: backup_assert_index
|
label: "backup-cmd-{{ backup_debug_index }}"
|
||||||
label: "backup-cmd-{{ backup_assert_index }}"
|
when: debug_level == 1
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
- name: Nextcloud | Fail if any backup command failed
|
||||||
# Upgrade
|
ansible.builtin.assert:
|
||||||
# -------------------------------------------------------------------------
|
that:
|
||||||
|
- item.rc == 0
|
||||||
|
fail_msg: |
|
||||||
|
Nextcloud backup command failed.
|
||||||
|
Command: {{ item.item }}
|
||||||
|
RC: {{ item.rc }}
|
||||||
|
|
||||||
- name: Nextcloud | Run upgrade commands on VM
|
STDERR:
|
||||||
ansible.builtin.command:
|
{{ item.stderr | default('') | trim }}
|
||||||
argv:
|
quiet: true
|
||||||
- sshpass
|
loop: "{{ nc_backup_cmds.results }}"
|
||||||
- -e
|
loop_control:
|
||||||
- ssh
|
index_var: backup_assert_index
|
||||||
- -o
|
label: "backup-cmd-{{ backup_assert_index }}"
|
||||||
- StrictHostKeyChecking=no
|
|
||||||
- -o
|
|
||||||
- UserKnownHostsFile=/dev/null
|
|
||||||
- -o
|
|
||||||
- ConnectTimeout=15
|
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
|
||||||
- >-
|
|
||||||
{{
|
|
||||||
('sudo -n bash -lc ' + (item | quote))
|
|
||||||
if vm_use_sudo
|
|
||||||
else
|
|
||||||
('bash -lc ' + (item | quote))
|
|
||||||
}}
|
|
||||||
environment:
|
|
||||||
SSHPASS: "{{ vm_pass }}"
|
|
||||||
loop: "{{ nextcloud_upgrade_commands }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: upgrade_index
|
|
||||||
label: "upgrade-cmd-{{ upgrade_index }}"
|
|
||||||
register: nc_upgrade_cmds
|
|
||||||
changed_when: false
|
|
||||||
failed_when: false
|
|
||||||
|
|
||||||
- name: Nextcloud | Show upgrade command outputs
|
# ---------------------------------------------------------------------
|
||||||
ansible.builtin.debug:
|
# Upgrade
|
||||||
msg: |
|
# ---------------------------------------------------------------------
|
||||||
CMD: {{ item.item }}
|
|
||||||
RC: {{ item.rc }}
|
|
||||||
STDOUT:
|
|
||||||
{{ item.stdout | default('') | trim }}
|
|
||||||
STDERR:
|
|
||||||
{{ item.stderr | default('') | trim }}
|
|
||||||
loop: "{{ nc_upgrade_cmds.results }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: upgrade_debug_index
|
|
||||||
label: "upgrade-cmd-{{ upgrade_debug_index }}"
|
|
||||||
when: debug_level == 1
|
|
||||||
|
|
||||||
- name: Nextcloud | Fail if any upgrade command failed
|
- name: Nextcloud | Run upgrade commands on VM
|
||||||
ansible.builtin.assert:
|
ansible.builtin.command:
|
||||||
that:
|
argv:
|
||||||
- item.rc == 0
|
- sshpass
|
||||||
fail_msg: >-
|
- -e
|
||||||
Nextcloud upgrade command failed:
|
- ssh
|
||||||
{{ item.item }}
|
- -o
|
||||||
(rc={{ item.rc }})
|
- 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_pass }}"
|
||||||
|
loop: "{{ nextcloud_upgrade_commands }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: upgrade_index
|
||||||
|
label: "upgrade-cmd-{{ upgrade_index }}"
|
||||||
|
register: nc_upgrade_cmds
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
STDERR:
|
- name: Nextcloud | Show upgrade command outputs
|
||||||
{{ item.stderr | default('') | trim }}
|
ansible.builtin.debug:
|
||||||
quiet: true
|
msg: |
|
||||||
loop: "{{ nc_upgrade_cmds.results }}"
|
CMD: {{ item.item }}
|
||||||
loop_control:
|
RC: {{ item.rc }}
|
||||||
index_var: upgrade_assert_index
|
|
||||||
label: "upgrade-cmd-{{ upgrade_assert_index }}"
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
STDOUT:
|
||||||
# Disable maintenance mode
|
{{ item.stdout | default('') | trim }}
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
- name: Nextcloud | Disable maintenance mode
|
STDERR:
|
||||||
ansible.builtin.command:
|
{{ item.stderr | default('') | trim }}
|
||||||
argv:
|
loop: "{{ nc_upgrade_cmds.results }}"
|
||||||
- sshpass
|
loop_control:
|
||||||
- -e
|
index_var: upgrade_debug_index
|
||||||
- ssh
|
label: "upgrade-cmd-{{ upgrade_debug_index }}"
|
||||||
- -o
|
when: debug_level == 1
|
||||||
- StrictHostKeyChecking=no
|
|
||||||
- -o
|
|
||||||
- UserKnownHostsFile=/dev/null
|
|
||||||
- -o
|
|
||||||
- ConnectTimeout=15
|
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
|
||||||
- >-
|
|
||||||
{{
|
|
||||||
(
|
|
||||||
'sudo -n bash -lc ' +
|
|
||||||
(
|
|
||||||
'docker exec -u www-data nextcloud ' +
|
|
||||||
'php occ maintenance:mode --off'
|
|
||||||
| quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if vm_use_sudo
|
|
||||||
else
|
|
||||||
(
|
|
||||||
'bash -lc ' +
|
|
||||||
(
|
|
||||||
'docker exec -u www-data nextcloud ' +
|
|
||||||
'php occ maintenance:mode --off'
|
|
||||||
| quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
environment:
|
|
||||||
SSHPASS: "{{ vm_pass }}"
|
|
||||||
register: nc_maint_off
|
|
||||||
changed_when: false
|
|
||||||
failed_when: false
|
|
||||||
|
|
||||||
- name: Nextcloud | Fail if maintenance mode could not be disabled
|
- name: Nextcloud | Fail if any upgrade command failed
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- nc_maint_off.rc == 0
|
- item.rc == 0
|
||||||
fail_msg: >-
|
fail_msg: |
|
||||||
Failed to disable Nextcloud maintenance mode
|
Nextcloud upgrade command failed.
|
||||||
(rc={{ nc_maint_off.rc }}).
|
Command: {{ item.item }}
|
||||||
|
RC: {{ item.rc }}
|
||||||
|
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ nc_maint_off.stderr | default('') | trim }}
|
{{ item.stderr | default('') | trim }}
|
||||||
quiet: true
|
quiet: true
|
||||||
|
loop: "{{ nc_upgrade_cmds.results }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: upgrade_assert_index
|
||||||
|
label: "upgrade-cmd-{{ upgrade_assert_index }}"
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Nextcloud | Disable maintenance mode
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- sshpass
|
||||||
|
- -e
|
||||||
|
- ssh
|
||||||
|
- -o
|
||||||
|
- StrictHostKeyChecking=no
|
||||||
|
- -o
|
||||||
|
- UserKnownHostsFile=/dev/null
|
||||||
|
- -o
|
||||||
|
- ConnectTimeout=15
|
||||||
|
- "{{ vm_user }}@{{ vm_ip }}"
|
||||||
|
- >-
|
||||||
|
{{
|
||||||
|
('sudo -n bash -lc ' ~
|
||||||
|
(nextcloud_maintenance_off_command | quote))
|
||||||
|
if vm_use_sudo
|
||||||
|
else
|
||||||
|
('bash -lc ' ~
|
||||||
|
(nextcloud_maintenance_off_command | quote))
|
||||||
|
}}
|
||||||
|
environment:
|
||||||
|
SSHPASS: "{{ vm_pass }}"
|
||||||
|
register: nc_maint_off
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Nextcloud | Show maintenance mode result
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: |
|
||||||
|
RC: {{ nc_maint_off.rc }}
|
||||||
|
|
||||||
|
STDOUT:
|
||||||
|
{{ nc_maint_off.stdout | default('') | trim }}
|
||||||
|
|
||||||
|
STDERR:
|
||||||
|
{{ nc_maint_off.stderr | default('') | trim }}
|
||||||
|
when: debug_level == 1
|
||||||
|
|
||||||
|
- name: Nextcloud | Fail if maintenance mode could not be disabled
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- nc_maint_off.rc == 0
|
||||||
|
fail_msg: |
|
||||||
|
Failed to disable Nextcloud maintenance mode.
|
||||||
|
RC: {{ nc_maint_off.rc }}
|
||||||
|
|
||||||
|
STDERR:
|
||||||
|
{{ nc_maint_off.stderr | default('') | trim }}
|
||||||
|
quiet: true
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# Readiness check
|
# Readiness check
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
- name: Nextcloud | Wait for status.php from controller
|
- name: Nextcloud | Wait for status.php
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
url: "{{ nextcloud_status_url }}"
|
url: "{{ nextcloud_status_url }}"
|
||||||
method: GET
|
method: GET
|
||||||
return_content: true
|
return_content: true
|
||||||
validate_certs: true
|
validate_certs: true
|
||||||
status_code: 200
|
status_code: 200
|
||||||
register: nc_status_controller
|
register: nc_status
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
run_once: true
|
run_once: true
|
||||||
retries: "{{ retry_count }}"
|
retries: "{{ retry_count }}"
|
||||||
delay: 4
|
delay: 4
|
||||||
until:
|
until:
|
||||||
- nc_status_controller.status | default(0) == 200
|
- nc_status.status | default(0) == 200
|
||||||
- nc_status_controller.json is defined
|
- nc_status.json is defined
|
||||||
failed_when: false
|
- nc_status.json.installed | default(false) | bool
|
||||||
|
- not (nc_status.json.maintenance | default(true) | bool)
|
||||||
|
- not (nc_status.json.needsDbUpgrade | default(true) | bool)
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Nextcloud | Fetch status.php from VM
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- sshpass
|
|
||||||
- -e
|
|
||||||
- ssh
|
|
||||||
- -o
|
|
||||||
- StrictHostKeyChecking=no
|
|
||||||
- -o
|
|
||||||
- UserKnownHostsFile=/dev/null
|
|
||||||
- -o
|
|
||||||
- ConnectTimeout=15
|
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
|
||||||
- >-
|
|
||||||
{{
|
|
||||||
(
|
|
||||||
'sudo -n bash -lc ' +
|
|
||||||
(
|
|
||||||
"python3 -c " +
|
|
||||||
(
|
|
||||||
"import urllib.request; " +
|
|
||||||
"print(urllib.request.urlopen(" +
|
|
||||||
nextcloud_status_url | quote +
|
|
||||||
", timeout=15).read().decode())"
|
|
||||||
) | quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if vm_use_sudo
|
|
||||||
else
|
|
||||||
(
|
|
||||||
'bash -lc ' +
|
|
||||||
(
|
|
||||||
"python3 -c " +
|
|
||||||
(
|
|
||||||
"import urllib.request; " +
|
|
||||||
"print(urllib.request.urlopen(" +
|
|
||||||
nextcloud_status_url | quote +
|
|
||||||
", timeout=15).read().decode())"
|
|
||||||
) | quote
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
environment:
|
|
||||||
SSHPASS: "{{ vm_pass }}"
|
|
||||||
register: nc_status_vm
|
|
||||||
changed_when: false
|
|
||||||
failed_when: false
|
|
||||||
when:
|
|
||||||
- nc_status_controller.status | default(0) != 200
|
|
||||||
or nc_status_controller.json is not defined
|
|
||||||
|
|
||||||
- name: Nextcloud | Use controller status JSON
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
nextcloud_status_json: "{{ nc_status_controller.json }}"
|
|
||||||
when:
|
|
||||||
- nc_status_controller.status | default(0) == 200
|
|
||||||
- nc_status_controller.json is defined
|
|
||||||
|
|
||||||
- name: Nextcloud | Use VM status JSON
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
nextcloud_status_json: "{{ nc_status_vm.stdout | trim | from_json }}"
|
|
||||||
when:
|
|
||||||
- nextcloud_status_json is not defined
|
|
||||||
- nc_status_vm is defined
|
|
||||||
- nc_status_vm.stdout | default('') | trim | length > 0
|
|
||||||
|
|
||||||
- name: Nextcloud | Validate final status
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- nextcloud_status_json is defined
|
|
||||||
- nextcloud_status_json.installed | default(false) | bool
|
|
||||||
- not (nextcloud_status_json.maintenance | default(true) | bool)
|
|
||||||
- not (nextcloud_status_json.needsDbUpgrade | default(true) | bool)
|
|
||||||
fail_msg: >-
|
|
||||||
Nextcloud is not ready after upgrade.
|
|
||||||
Status: {{ nextcloud_status_json | default('unavailable') }}
|
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Nextcloud | Print final status
|
- name: Nextcloud | Print final status
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
Nextcloud {{ nextcloud_status_json.version | default('?') }}
|
Nextcloud {{ nc_status.json.version | default('?') }}
|
||||||
(installed={{ nextcloud_status_json.installed | default('?') }},
|
(installed={{ nc_status.json.installed | default('?') }},
|
||||||
maintenance={{ nextcloud_status_json.maintenance | default('?') }},
|
maintenance={{ nc_status.json.maintenance | default('?') }},
|
||||||
needsDbUpgrade={{
|
needsDbUpgrade={{
|
||||||
nextcloud_status_json.needsDbUpgrade | default('?')
|
nc_status.json.needsDbUpgrade | default('?')
|
||||||
}})
|
}})
|
||||||
Reference in New Issue
Block a user