forked from jakub/ansible
.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
# nextcloud/update_uptime_kuma.yml
|
||||||
|
|
||||||
- name: Update Uptime Kuma on VM via Proxmox
|
- name: Update Uptime Kuma on VM via Proxmox
|
||||||
hosts: proxmox
|
hosts: proxmox
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -26,6 +28,10 @@
|
|||||||
# Fixed container name used in your compose (conflicts with previous/Portainer-run container)
|
# Fixed container name used in your compose (conflicts with previous/Portainer-run container)
|
||||||
kuma_container_name: "uptime-kuma-dev"
|
kuma_container_name: "uptime-kuma-dev"
|
||||||
|
|
||||||
|
# Retry policy (to mirror Collabora play): 10x with 2s delay
|
||||||
|
kuma_retries: 25
|
||||||
|
kuma_delay: 2
|
||||||
|
|
||||||
# Docker command prefix (consistent behavior)
|
# Docker command prefix (consistent behavior)
|
||||||
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
||||||
|
|
||||||
@@ -33,9 +39,8 @@
|
|||||||
kuma_commands:
|
kuma_commands:
|
||||||
- "{{ docker_prefix }} pull -q {{ kuma_image }} >/dev/null"
|
- "{{ docker_prefix }} pull -q {{ kuma_image }} >/dev/null"
|
||||||
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} pull {{ kuma_service }} >/dev/null"
|
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} pull {{ kuma_service }} >/dev/null"
|
||||||
# --- added: gently remove conflicting container name before compose up ---
|
# remove conflicting container name before compose up (silently)
|
||||||
- "{{ docker_prefix }} rm -f {{ kuma_container_name }} >/dev/null 2>&1 || true"
|
- "{{ docker_prefix }} rm -f {{ kuma_container_name }} >/dev/null 2>&1 || true"
|
||||||
# ------------------------------------------------------------------------
|
|
||||||
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} up -d --no-deps --force-recreate {{ kuma_service }} >/dev/null"
|
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} up -d --no-deps --force-recreate {{ kuma_service }} >/dev/null"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
@@ -86,7 +91,7 @@
|
|||||||
# Readiness checks (controller first, then VM fallback)
|
# Readiness checks (controller first, then VM fallback)
|
||||||
# -------------------------
|
# -------------------------
|
||||||
|
|
||||||
- name: Kuma | Wait for homepage (controller first)
|
- name: Kuma | Wait for homepage (controller first, with retries)
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
url: "{{ (kuma_url | regex_replace('/$','')) + '/' }}"
|
url: "{{ (kuma_url | regex_replace('/$','')) + '/' }}"
|
||||||
method: GET
|
method: GET
|
||||||
@@ -98,13 +103,13 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
run_once: true
|
run_once: true
|
||||||
when: kuma_url is defined and (kuma_url | length) > 0
|
when: kuma_url is defined and (kuma_url | length) > 0
|
||||||
retries: 10
|
retries: "{{ kuma_retries }}"
|
||||||
delay: 2
|
delay: "{{ kuma_delay }}"
|
||||||
until: kuma_controller.status == 200
|
until: kuma_controller.status == 200
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Kuma | VM-side fetch (HTML via Python)
|
- name: Kuma | VM-side fetch (HTML via Python, with retries)
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
@@ -132,26 +137,33 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined
|
when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined
|
||||||
|
retries: "{{ kuma_retries }}"
|
||||||
|
delay: "{{ kuma_delay }}"
|
||||||
|
# Wait until we actually got some HTML that likely belongs to Kuma
|
||||||
|
until: (kuma_vm.stdout | default('') | trim | length) > 0 and ('Uptime Kuma' in (kuma_vm.stdout | default('')))
|
||||||
|
|
||||||
- name: Kuma | Choose homepage HTML (controller wins, else VM)
|
- name: Kuma | Choose homepage HTML (controller wins, else VM) # safe guard against empty result
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
kuma_home_html: >-
|
kuma_home_html: >-
|
||||||
{{
|
{{
|
||||||
(kuma_controller.content
|
(
|
||||||
if (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined)
|
kuma_controller.content
|
||||||
else (
|
if (kuma_controller is defined)
|
||||||
(kuma_vm.stdout | default('') | trim | length > 0)
|
and ((kuma_controller.status|default(0))==200)
|
||||||
| ternary((kuma_vm.stdout | trim), omit)
|
and (kuma_controller.content is defined)
|
||||||
)
|
else
|
||||||
|
(kuma_vm.stdout | default('') | trim)
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
failed_when: false
|
when:
|
||||||
|
- (kuma_controller is defined and (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined))
|
||||||
|
or ((kuma_vm.stdout | default('') | trim | length) > 0)
|
||||||
|
|
||||||
- name: Kuma | Print concise summary
|
- name: Kuma | Print concise summary
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
Uptime Kuma homepage {{ 'reachable' if (kuma_home_html is defined) else 'NOT reachable' }}.
|
Uptime Kuma homepage {{ 'reachable' if (kuma_home_html is defined) else 'NOT reachable' }}.
|
||||||
Source={{ 'controller' if ((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' }};
|
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 }};
|
length={{ (kuma_home_html | default('')) | length }};
|
||||||
contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }}
|
contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
# nextcloud/update_uptime_kuma.yml
|
|
||||||
|
|
||||||
- name: Update Uptime Kuma on VM via Proxmox
|
- name: Update Uptime Kuma on VM via Proxmox
|
||||||
hosts: proxmox
|
hosts: proxmox
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -28,10 +26,6 @@
|
|||||||
# Fixed container name used in your compose (conflicts with previous/Portainer-run container)
|
# Fixed container name used in your compose (conflicts with previous/Portainer-run container)
|
||||||
kuma_container_name: "uptime-kuma-dev"
|
kuma_container_name: "uptime-kuma-dev"
|
||||||
|
|
||||||
# Retry policy (to mirror Collabora play): 10x with 2s delay
|
|
||||||
kuma_retries: 25
|
|
||||||
kuma_delay: 2
|
|
||||||
|
|
||||||
# Docker command prefix (consistent behavior)
|
# Docker command prefix (consistent behavior)
|
||||||
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
||||||
|
|
||||||
@@ -39,8 +33,9 @@
|
|||||||
kuma_commands:
|
kuma_commands:
|
||||||
- "{{ docker_prefix }} pull -q {{ kuma_image }} >/dev/null"
|
- "{{ docker_prefix }} pull -q {{ kuma_image }} >/dev/null"
|
||||||
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} pull {{ kuma_service }} >/dev/null"
|
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} pull {{ kuma_service }} >/dev/null"
|
||||||
# remove conflicting container name before compose up (silently)
|
# --- added: gently remove conflicting container name before compose up ---
|
||||||
- "{{ docker_prefix }} rm -f {{ kuma_container_name }} >/dev/null 2>&1 || true"
|
- "{{ docker_prefix }} rm -f {{ kuma_container_name }} >/dev/null 2>&1 || true"
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} up -d --no-deps --force-recreate {{ kuma_service }} >/dev/null"
|
- "{{ docker_prefix }} compose -p {{ kuma_project }} -f {{ kuma_compose_file }} up -d --no-deps --force-recreate {{ kuma_service }} >/dev/null"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
@@ -91,7 +86,7 @@
|
|||||||
# Readiness checks (controller first, then VM fallback)
|
# Readiness checks (controller first, then VM fallback)
|
||||||
# -------------------------
|
# -------------------------
|
||||||
|
|
||||||
- name: Kuma | Wait for homepage (controller first, with retries)
|
- name: Kuma | Wait for homepage (controller first)
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
url: "{{ (kuma_url | regex_replace('/$','')) + '/' }}"
|
url: "{{ (kuma_url | regex_replace('/$','')) + '/' }}"
|
||||||
method: GET
|
method: GET
|
||||||
@@ -103,13 +98,13 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
run_once: true
|
run_once: true
|
||||||
when: kuma_url is defined and (kuma_url | length) > 0
|
when: kuma_url is defined and (kuma_url | length) > 0
|
||||||
retries: "{{ kuma_retries }}"
|
retries: 10
|
||||||
delay: "{{ kuma_delay }}"
|
delay: 2
|
||||||
until: kuma_controller.status == 200
|
until: kuma_controller.status == 200
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Kuma | VM-side fetch (HTML via Python, with retries)
|
- name: Kuma | VM-side fetch (HTML via Python)
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
@@ -137,33 +132,26 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined
|
when: kuma_controller.status | default(0) != 200 or kuma_controller.content is not defined
|
||||||
retries: "{{ kuma_retries }}"
|
|
||||||
delay: "{{ kuma_delay }}"
|
|
||||||
# Wait until we actually got some HTML that likely belongs to Kuma
|
|
||||||
until: (kuma_vm.stdout | default('') | trim | length) > 0 and ('Uptime Kuma' in (kuma_vm.stdout | default('')))
|
|
||||||
|
|
||||||
- name: Kuma | Choose homepage HTML (controller wins, else VM) # safe guard against empty result
|
- name: Kuma | Choose homepage HTML (controller wins, else VM)
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
kuma_home_html: >-
|
kuma_home_html: >-
|
||||||
{{
|
{{
|
||||||
(
|
(kuma_controller.content
|
||||||
kuma_controller.content
|
if (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined)
|
||||||
if (kuma_controller is defined)
|
else (
|
||||||
and ((kuma_controller.status|default(0))==200)
|
(kuma_vm.stdout | default('') | trim | length > 0)
|
||||||
and (kuma_controller.content is defined)
|
| ternary((kuma_vm.stdout | trim), omit)
|
||||||
else
|
)
|
||||||
(kuma_vm.stdout | default('') | trim)
|
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
when:
|
failed_when: false
|
||||||
- (kuma_controller is defined and (kuma_controller.status|default(0))==200 and (kuma_controller.content is defined))
|
|
||||||
or ((kuma_vm.stdout | default('') | trim | length) > 0)
|
|
||||||
|
|
||||||
- name: Kuma | Print concise summary
|
- name: Kuma | Print concise summary
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
Uptime Kuma homepage {{ 'reachable' if (kuma_home_html is defined) else 'NOT reachable' }}.
|
Uptime Kuma homepage {{ 'reachable' if (kuma_home_html is defined) else 'NOT reachable' }}.
|
||||||
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' }};
|
Source={{ 'controller' if ((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 }};
|
length={{ (kuma_home_html | default('')) | length }};
|
||||||
contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }}
|
contains('Uptime Kuma')={{ (kuma_home_html is defined) and ('Uptime Kuma' in kuma_home_html) }}
|
||||||
|
|
||||||
Reference in New Issue
Block a user