forked from jakub/ansible
.
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
# Fixed container name used in your compose (conflicts with previous/Portainer-run container)
|
||||
kuma_container_name: "uptime-kuma-dev"
|
||||
|
||||
# Retry policy (to mirror Collabora play): 25x with 2s delay
|
||||
# Retry policy
|
||||
kuma_retries: "{{ RETRIES }}"
|
||||
kuma_delay: 2
|
||||
|
||||
@@ -54,12 +54,11 @@
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Run Uptime Kuma update commands on VM (via SSH)
|
||||
- name: Run Uptime Kuma update commands on VM (via SSH) # use SSHPASS env, hide item label
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
- -p
|
||||
- "{{ vm_pass }}"
|
||||
- -e # read password from SSHPASS environment
|
||||
- ssh
|
||||
- -o
|
||||
- StrictHostKeyChecking=no
|
||||
@@ -69,10 +68,15 @@
|
||||
- bash
|
||||
- -lc
|
||||
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
||||
environment:
|
||||
SSHPASS: "{{ vm_pass }}" # supply password via environment
|
||||
loop: "{{ kuma_commands }}"
|
||||
loop_control:
|
||||
index_var: idx # capture loop index
|
||||
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
|
||||
register: kuma_cmds
|
||||
changed_when: false
|
||||
no_log: "{{ DEBUG == 0 }}" # 🔒 Hide sensitive info when not debugging
|
||||
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging
|
||||
|
||||
- name: Show outputs for each Uptime Kuma command
|
||||
ansible.builtin.debug:
|
||||
@@ -86,12 +90,15 @@
|
||||
loop: "{{ kuma_cmds.results }}"
|
||||
when: DEBUG == 1
|
||||
|
||||
- name: Fail play if any Uptime Kuma command failed
|
||||
- name: Fail play if any Uptime Kuma command failed # also hide item label
|
||||
ansible.builtin.assert:
|
||||
that: "item.rc == 0"
|
||||
fail_msg: "Uptime Kuma update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
||||
success_msg: "All Uptime Kuma update commands succeeded."
|
||||
loop: "{{ kuma_cmds.results }}"
|
||||
loop_control:
|
||||
index_var: idx
|
||||
label: "cmd-{{ idx }}"
|
||||
|
||||
# -------------------------
|
||||
# Readiness checks (controller first, then VM fallback)
|
||||
@@ -115,12 +122,11 @@
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: Kuma | VM-side fetch (HTML via Python, with retries)
|
||||
- name: Kuma | VM-side fetch (HTML via Python, with retries) # use SSHPASS env here too
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
- -p
|
||||
- "{{ vm_pass }}"
|
||||
- -e
|
||||
- ssh
|
||||
- -o
|
||||
- StrictHostKeyChecking=no
|
||||
@@ -139,6 +145,8 @@
|
||||
except Exception:
|
||||
pass
|
||||
PY
|
||||
environment:
|
||||
SSHPASS: "{{ vm_pass }}"
|
||||
register: kuma_vm
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
@@ -146,7 +154,7 @@
|
||||
retries: "{{ kuma_retries }}"
|
||||
delay: "{{ kuma_delay }}"
|
||||
until: (kuma_vm.stdout | default('') | trim | length) > 0 and ('Uptime Kuma' in (kuma_vm.stdout | default('')))
|
||||
no_log: "{{ DEBUG == 0 }}" # 🔒 Hide command and output when not debugging
|
||||
no_log: "{{ DEBUG == 0 }}" # hide command and output when not debugging
|
||||
|
||||
- name: Kuma | Choose homepage HTML (controller wins, else VM) # safe guard against empty result
|
||||
ansible.builtin.set_fact:
|
||||
@@ -172,7 +180,7 @@
|
||||
Source={{ 'controller' if ((kuma_controller is defined) and (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined)) else 'vm' if (kuma_vm.stdout|default('')|trim|length>0) else 'n/a' }};
|
||||
length={{ (kuma_home_html | default('')) | length }};
|
||||
contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }}
|
||||
when: DEBUG == 1 # 🪵 Only print in debug mode
|
||||
when: DEBUG == 1
|
||||
|
||||
- name: Kuma | Homepage unavailable (after retries)
|
||||
ansible.builtin.debug:
|
||||
@@ -183,4 +191,4 @@
|
||||
- name: Kuma | HTML excerpt (debug)
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ (kuma_home_html | default(''))[:500] }}"
|
||||
when: kuma_home_html is defined and DEBUG == 1
|
||||
when: kuma_home_html is defined and DEBUG == 1
|
||||
|
||||
Reference in New Issue
Block a user