forked from jakub/ansible
Compare commits
5 Commits
0fd5ef9e41
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af3c676183 | ||
|
|
c2d67f5498 | ||
|
|
a1d730a18c | ||
|
|
cf2507bdf6 | ||
|
|
21ce9478f4 |
@@ -39,39 +39,16 @@
|
||||
|
||||
# Docker command prefix (consistent behavior and quiet hints)
|
||||
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
||||
|
||||
|
||||
# Commands to run on the target VM (quiet outputs)
|
||||
# 1) Check directory exists (we do NOT create anything, to stay safe)
|
||||
# 2) Safely download latest docker-compose.yml from GitHub (with backup)
|
||||
# 3) Pull images according to compose
|
||||
# 4) Start / update stack
|
||||
# 1) Download latest docker-compose.yml from GitHub (with backup)
|
||||
# 2) Pull images according to compose
|
||||
# 3) Start / update stack
|
||||
immich_commands:
|
||||
- >-
|
||||
[ -d "{{ immich_compose_dir }}" ] || {
|
||||
echo "ERROR: Directory {{ immich_compose_dir }} does not exist on VM; not touching anything." >&2;
|
||||
exit 1;
|
||||
}
|
||||
- >-
|
||||
cd "{{ immich_compose_dir }}" &&
|
||||
wget -qO docker-compose.yml.new "{{ immich_compose_url }}" || {
|
||||
echo "ERROR: Failed to download docker-compose.yml from GitHub; keeping existing one." >&2;
|
||||
rm -f docker-compose.yml.new 2>/dev/null || true;
|
||||
exit 1;
|
||||
};
|
||||
if [ -s docker-compose.yml.new ]; then
|
||||
echo "Downloaded new docker-compose.yml from GitHub (Immich latest).";
|
||||
if [ -f docker-compose.yml ]; then
|
||||
cp docker-compose.yml "docker-compose.yml.bak-$(date +%F_%H-%M-%S)";
|
||||
echo "Existing docker-compose.yml backed up.";
|
||||
fi;
|
||||
mv docker-compose.yml.new docker-compose.yml;
|
||||
else
|
||||
echo "WARNING: Downloaded docker-compose.yml.new is empty; keeping existing one." >&2;
|
||||
rm -f docker-compose.yml.new 2>/dev/null || true;
|
||||
exit 1;
|
||||
fi
|
||||
- "cd {{ immich_compose_dir }} && wget -qO docker-compose.yml.new {{ immich_compose_url }} || true; if [ -s docker-compose.yml.new ]; then echo 'Downloaded new docker-compose.yml from GitHub (Immich latest).'; if [ -f docker-compose.yml ]; then cp docker-compose.yml docker-compose.yml.bak-$(date +%F_%H-%M-%S); echo 'Existing docker-compose.yml backed up.'; fi; mv docker-compose.yml.new docker-compose.yml; else echo 'WARNING: Failed to download a valid docker-compose.yml, keeping existing one.' >&2; rm -f docker-compose.yml.new 2>/dev/null || true; fi"
|
||||
- "{{ docker_prefix }} compose -p {{ immich_project }} -f {{ immich_compose_file }} pull >/dev/null"
|
||||
- "{{ docker_prefix }} compose -p {{ immich_project }} -f {{ immich_compose_file }} up -d --remove-orphans >/dev/null"
|
||||
- "{{ docker_prefix }} compose -p {{ immich_project }} -f {{ immich_compose_file }} up -d --remove-orphans --force-recreate >/dev/null"
|
||||
# - "{{ docker_prefix }} compose -p {{ immich_project }} -f {{ immich_compose_file }} up -d --remove-orphans >/dev/null"
|
||||
|
||||
|
||||
tasks:
|
||||
@@ -85,7 +62,7 @@
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
- -e # read password from SSHPASS environment
|
||||
- -e
|
||||
- ssh
|
||||
- -o
|
||||
- StrictHostKeyChecking=no
|
||||
@@ -96,14 +73,15 @@
|
||||
- -lc
|
||||
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
||||
environment:
|
||||
SSHPASS: "{{ vm_pass }}" # supply password via environment
|
||||
SSHPASS: "{{ vm_pass }}"
|
||||
loop: "{{ immich_commands }}"
|
||||
loop_control:
|
||||
index_var: idx # capture loop index
|
||||
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
|
||||
index_var: idx
|
||||
label: "cmd-{{ idx }}"
|
||||
register: immich_cmds
|
||||
changed_when: false
|
||||
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging
|
||||
no_log: "{{ DEBUG == 0 }}"
|
||||
run_once: true # <<< přidat
|
||||
|
||||
- name: Show outputs for each Immich command
|
||||
ansible.builtin.debug:
|
||||
@@ -117,7 +95,7 @@
|
||||
loop: "{{ immich_cmds.results }}"
|
||||
when: DEBUG == 1
|
||||
|
||||
- name: Fail play if any Immich command failed # also hide item label
|
||||
- name: Fail play if any Immich command failed
|
||||
ansible.builtin.assert:
|
||||
that: "item.rc == 0"
|
||||
fail_msg: "Immich update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
||||
@@ -126,6 +104,7 @@
|
||||
loop_control:
|
||||
index_var: idx
|
||||
label: "cmd-{{ idx }}"
|
||||
run_once: true
|
||||
|
||||
# -------------------------
|
||||
# Readiness checks (controller first, then VM fallback)
|
||||
|
||||
Reference in New Issue
Block a user