forked from jakub/ansible
test2
This commit is contained in:
@@ -1,43 +1,115 @@
|
||||
# nextcloud/check_stack_nextcloud.yml
|
||||
|
||||
- name: Run Nextcloud maintenance
|
||||
hosts: nextcloud
|
||||
- name: Run Nextcloud maintenance on VM via Proxmox
|
||||
hosts: proxmox_nextcloud
|
||||
gather_facts: false
|
||||
become: true
|
||||
become_user: root
|
||||
become_method: sudo
|
||||
|
||||
vars:
|
||||
# Internal normalized variables
|
||||
vm_use_sudo: "{{ use_sudo | default(false) | bool }}"
|
||||
|
||||
vm_commands:
|
||||
- "docker exec -u www-data nextcloud php -f /var/www/html/cron.php"
|
||||
- "docker exec -u www-data nextcloud php occ app:update --all"
|
||||
- "docker exec -u www-data nextcloud php occ maintenance:repair --include-expensive"
|
||||
- "docker exec -u www-data nextcloud php occ status"
|
||||
- "set -o pipefail; timeout 180s bash -x /data/compose/nextcloud/stack-health.sh </dev/null"
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php -f /var/www/html/cron.php
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ app:update --all
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ maintenance:repair --include-expensive
|
||||
|
||||
- >-
|
||||
docker exec -u www-data nextcloud
|
||||
php occ status
|
||||
|
||||
- >-
|
||||
set -o pipefail;
|
||||
timeout 180s bash -x
|
||||
/data/compose/nextcloud/stack-health.sh
|
||||
</dev/null
|
||||
|
||||
pre_tasks:
|
||||
- name: Validate VM connection variables
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- vm_ip is defined
|
||||
- vm_ip | string | trim | length > 0
|
||||
- vm_user is defined
|
||||
- vm_user | string | trim | length > 0
|
||||
- vm_pass is defined
|
||||
- vm_pass | string | length > 0
|
||||
fail_msg: >-
|
||||
Missing vm_ip, vm_user or vm_pass.
|
||||
Configure these variables in the attached Semaphore Variable Group.
|
||||
quiet: true
|
||||
no_log: true
|
||||
|
||||
tasks:
|
||||
- name: Run Nextcloud commands
|
||||
ansible.builtin.shell:
|
||||
cmd: "{{ item }}"
|
||||
executable: /bin/bash
|
||||
- name: Ensure sshpass is installed
|
||||
ansible.builtin.apt:
|
||||
name: sshpass
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Run Nextcloud commands on 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 ' + (item | quote))
|
||||
if vm_use_sudo
|
||||
else
|
||||
('bash -lc ' + (item | quote))
|
||||
}}
|
||||
environment:
|
||||
SSHPASS: "{{ vm_pass }}"
|
||||
loop: "{{ vm_commands }}"
|
||||
loop_control:
|
||||
label: "{{ item }}"
|
||||
register: vm_cmds
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Show command outputs
|
||||
- name: Show outputs for each command
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
CMD: {{ item.item }}
|
||||
RC: {{ item.rc }}
|
||||
RC: {{ item.rc }}
|
||||
STDOUT:
|
||||
{{ item.stdout | default('') }}
|
||||
{{ (item.stdout | default('') | trim) }}
|
||||
STDERR:
|
||||
{{ item.stderr | default('') }}
|
||||
{{ (item.stderr | default('') | trim) }}
|
||||
loop: "{{ vm_cmds.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Fail when a command failed
|
||||
- name: Fail play if any command failed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.rc == 0
|
||||
fail_msg: "Command failed: {{ item.item }} (rc={{ item.rc }})"
|
||||
fail_msg: >-
|
||||
Command failed on VM: {{ item.item }}
|
||||
(rc={{ item.rc }})
|
||||
|
||||
STDERR:
|
||||
{{ item.stderr | default('') | trim }}
|
||||
quiet: true
|
||||
loop: "{{ vm_cmds.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
Reference in New Issue
Block a user