test change semaphore

This commit is contained in:
martin.fencl
2025-12-21 11:18:21 +01:00
parent 75f4e8611f
commit 54b0dc86c8

View File

@@ -29,7 +29,7 @@
state: present
update_cache: yes
- name: Run Semaphore self-update on VM in background (nohup)
- name: Run Semaphore self-update on VM in background (nohup + log)
ansible.builtin.command:
argv:
- sshpass
@@ -43,19 +43,56 @@
- bash
- -lc
- |
nohup bash -c '
set -euo pipefail
# English comments: create unique run id and log paths
RID="$(date +%s)"
LOG="/tmp/semaphore-self-update-${RID}.log"
PIDF="/tmp/semaphore-self-update-${RID}.pid"
RCF="/tmp/semaphore-self-update-${RID}.rc"
# English comments: build docker command (optionally via sudo -n)
DOCKER="docker"
if [ "${USE_SUDO:-0}" = "1" ]; then
DOCKER="sudo -n docker"
fi
# English comments: start background worker, delay to let Semaphore job finish
nohup bash -lc "
set -euo pipefail
unalias docker 2>/dev/null || true
DOCKER_CLI_HINTS=0 docker compose \
-p {{ semaphore_project }} \
-f {{ semaphore_compose_file }} \
up -d --no-deps --force-recreate --pull always {{ semaphore_service }}
' >/dev/null 2>&1 &
export DOCKER_CLI_HINTS=0
echo \"=== started: \$(date -Is) ===\"
echo \"host: \$(hostname)\"
echo \"compose: {{ semaphore_compose_file }}\"
echo \"project: {{ semaphore_project }} service: {{ semaphore_service }}\"
echo \"USE_SUDO=\${USE_SUDO:-0}\"
echo
sleep 15
# English comments: pull explicitly (more compatible than --pull always)
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} pull {{ semaphore_service }}
# English comments: recreate service
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} up -d --no-deps --force-recreate {{ semaphore_service }}
echo
echo \"=== finished: \$(date -Is) ===\"
" >\"$LOG\" 2>&1 </dev/null &
echo $! >\"$PIDF\"
echo \"scheduled: pid=\$(cat \"$PIDF\"), log=$LOG\"
environment:
SSHPASS: "{{ vm_pass }}"
# Set USE_SUDO=1 in Semaphore env vars if vm_user needs sudo for docker
USE_SUDO: "{{ lookup('env', 'USE_SUDO') | default('0') }}"
register: semaphore_update
changed_when: false
no_log: "{{ DEBUG == 0 }}"
- name: Show result of Semaphore self-update (debug)
ansible.builtin.debug:
msg: |