3
0
forked from jakub/ansible

Compare commits

...

3 Commits

Author SHA1 Message Date
martin.fencl
af3c676183 edit 2025-12-10 12:41:42 +01:00
martin.fencl
c2d67f5498 edit 2025-12-10 12:31:17 +01:00
martin.fencl
a1d730a18c edit 2025-12-10 12:25:58 +01:00

View File

@@ -39,7 +39,7 @@
# 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) Download latest docker-compose.yml from GitHub (with backup)
# 2) Pull images according to compose
@@ -47,7 +47,8 @@
immich_commands:
- "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:
@@ -57,8 +58,7 @@
state: present
update_cache: yes
- name: Immich | Check compose directory exists on VM
- name: Run Immich update commands on VM (via SSH) # use SSHPASS env, hide item value
ansible.builtin.command:
argv:
- sshpass
@@ -71,37 +71,17 @@
- "{{ vm_user }}@{{ vm_ip }}"
- bash
- -lc
- "test -d {{ immich_compose_dir }}"
environment:
SSHPASS: "{{ vm_pass }}"
register: immich_dir
changed_when: false
failed_when: immich_dir.rc != 0
- name: Run Immich update commands on VM (via SSH) # use SSHPASS env, hide item value
ansible.builtin.command:
argv:
- sshpass
- -e # read password from SSHPASS environment
- ssh
- -o
- StrictHostKeyChecking=no
- -o
- ConnectTimeout=15
- "{{ vm_user }}@{{ vm_ip }}"
- bash
- -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:
@@ -115,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 }})"
@@ -124,6 +104,7 @@
loop_control:
index_var: idx
label: "cmd-{{ idx }}"
run_once: true
# -------------------------
# Readiness checks (controller first, then VM fallback)