forked from jakub/ansible
test
This commit is contained in:
@@ -1,21 +1,11 @@
|
|||||||
# nextcloud/check_stack_nextcloud.yml
|
# nextcloud/check_stack_nextcloud.yml
|
||||||
|
|
||||||
- name: Run Nextcloud maintenance on VM via Proxmox
|
- name: Run Nextcloud maintenance
|
||||||
hosts: proxmox_nextcloud
|
hosts: nextcloud
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
become: true
|
become: true
|
||||||
become_user: root
|
|
||||||
become_method: sudo
|
|
||||||
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
vm_ip: "{{ lookup('env', 'VM_IP') }}"
|
|
||||||
vm_user: "{{ lookup('env', 'VM_USER') }}"
|
|
||||||
vm_pass: "{{ lookup('env', 'VM_PASS') }}"
|
|
||||||
|
|
||||||
# Flip to true if Docker needs sudo on the VM
|
|
||||||
use_sudo: false
|
|
||||||
|
|
||||||
vm_commands:
|
vm_commands:
|
||||||
- "docker exec -u www-data nextcloud php -f /var/www/html/cron.php"
|
- "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 app:update --all"
|
||||||
@@ -24,45 +14,30 @@
|
|||||||
- "set -o pipefail; timeout 180s bash -x /data/compose/nextcloud/stack-health.sh </dev/null"
|
- "set -o pipefail; timeout 180s bash -x /data/compose/nextcloud/stack-health.sh </dev/null"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Ensure sshpass is installed (for password-based SSH) # English comments
|
- name: Run Nextcloud commands
|
||||||
ansible.builtin.apt:
|
ansible.builtin.shell:
|
||||||
name: sshpass
|
cmd: "{{ item }}"
|
||||||
state: present
|
executable: /bin/bash
|
||||||
update_cache: yes
|
|
||||||
|
|
||||||
- name: Run Nextcloud commands on VM (via SSH, argv, no line breaks)
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- sshpass
|
|
||||||
- -p
|
|
||||||
- "{{ vm_pass }}"
|
|
||||||
- ssh
|
|
||||||
- -o
|
|
||||||
- StrictHostKeyChecking=no
|
|
||||||
- -o
|
|
||||||
- ConnectTimeout=15
|
|
||||||
- "{{ vm_user }}@{{ vm_ip }}"
|
|
||||||
- bash
|
|
||||||
- -lc
|
|
||||||
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
|
||||||
loop: "{{ vm_commands }}"
|
loop: "{{ vm_commands }}"
|
||||||
register: vm_cmds
|
register: vm_cmds
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
- name: Show outputs for each command
|
- name: Show command outputs
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
CMD: {{ item.item }}
|
CMD: {{ item.item }}
|
||||||
RC: {{ item.rc }}
|
RC: {{ item.rc }}
|
||||||
STDOUT:
|
STDOUT:
|
||||||
{{ (item.stdout | default('')).strip() }}
|
{{ item.stdout | default('') }}
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ (item.stderr | default('')).strip() }}
|
{{ item.stderr | default('') }}
|
||||||
loop: "{{ vm_cmds.results }}"
|
loop: "{{ vm_cmds.results }}"
|
||||||
|
|
||||||
- name: Fail play if any command failed
|
- name: Fail when a command failed
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: "item.rc == 0"
|
that:
|
||||||
fail_msg: "Command failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
- item.rc == 0
|
||||||
success_msg: "All commands succeeded."
|
fail_msg: "Command failed: {{ item.item }} (rc={{ item.rc }})"
|
||||||
|
quiet: true
|
||||||
loop: "{{ vm_cmds.results }}"
|
loop: "{{ vm_cmds.results }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user