3
0
forked from jakub/ansible

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 state: present
update_cache: yes 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: ansible.builtin.command:
argv: argv:
- sshpass - sshpass
@@ -43,19 +43,56 @@
- bash - bash
- -lc - -lc
- | - |
nohup bash -c ' set -euo pipefail
unalias docker 2>/dev/null || true
DOCKER_CLI_HINTS=0 docker compose \ # English comments: create unique run id and log paths
-p {{ semaphore_project }} \ RID="$(date +%s)"
-f {{ semaphore_compose_file }} \ LOG="/tmp/semaphore-self-update-${RID}.log"
up -d --no-deps --force-recreate --pull always {{ semaphore_service }} PIDF="/tmp/semaphore-self-update-${RID}.pid"
' >/dev/null 2>&1 & 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
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: environment:
SSHPASS: "{{ vm_pass }}" 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 register: semaphore_update
changed_when: false changed_when: false
no_log: "{{ DEBUG == 0 }}" no_log: "{{ DEBUG == 0 }}"
- name: Show result of Semaphore self-update (debug) - name: Show result of Semaphore self-update (debug)
ansible.builtin.debug: ansible.builtin.debug:
msg: | msg: |