3
0
forked from jakub/ansible

Compare commits

..

8 Commits

Author SHA1 Message Date
martin.fencl
5e9d755390 add immich 4 2025-12-16 11:58:09 +01:00
martin.fencl
73cf848f82 . 2025-12-16 11:27:19 +01:00
martin.fencl
e4dac7808b add immich 3 2025-12-16 11:16:13 +01:00
martin.fencl
f61addc2be add immich 2 2025-12-16 11:10:50 +01:00
martin.fencl
94f3de1e7d add immich 2025-12-16 11:04:23 +01:00
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
2 changed files with 403 additions and 109 deletions

View File

@@ -8,7 +8,7 @@
become_method: sudo become_method: sudo
vars: vars:
# --- Connection to VM (provided by Semaphore env vars) --- # VM connection (provided by Semaphore env vars)
vm_ip: "{{ lookup('env', 'VM_IP') }}" vm_ip: "{{ lookup('env', 'VM_IP') }}"
vm_user: "{{ lookup('env', 'VM_USER') }}" vm_user: "{{ lookup('env', 'VM_USER') }}"
vm_pass: "{{ lookup('env', 'VM_PASS') }}" vm_pass: "{{ lookup('env', 'VM_PASS') }}"
@@ -18,37 +18,179 @@
DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}" DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}"
RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}" RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}"
# --- Immich specifics --- # Immich specifics
immich_dir: "/opt/immich"
immich_project: "immich" immich_project: "immich"
# Where compose file lives on the VM
immich_compose_dir: "/opt/immich"
immich_compose_file: "{{ immich_compose_dir }}/docker-compose.yml"
# Official Immich compose URL (latest release)
immich_compose_url: "https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml" immich_compose_url: "https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml"
immich_compose_file: "/opt/immich/docker-compose.yml"
immich_override_file: "/opt/immich/docker-compose.override.yml"
immich_port: 2283 immich_port: 2283
# Optional external URL for controller-side readiness check # Optional external URL for controller-side readiness check (e.g., https://photos.example.com)
# Default to https://photos.martinfencl.eu/photos if IMMICH_URL is not set immich_url: "{{ lookup('env', 'IMMICH_URL') | default('', true) }}"
immich_url: "{{ lookup('env', 'IMMICH_URL') | default('https://photos.martinfencl.eu/photos', true) }}"
# Retry policy
immich_retries: "{{ RETRIES }}" immich_retries: "{{ RETRIES }}"
immich_delay: 2 immich_delay: 2
# Docker command prefix (consistent behavior and quiet hints) # 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"
# Commands to run on the target VM (quiet outputs) # Compose command (always include override to keep local mounts separate from upstream compose)
# 1) Download latest docker-compose.yml from GitHub (with backup) immich_compose_cmd: >-
# 2) Pull images according to compose {{ docker_prefix }} compose
# 3) Start / update stack -p {{ immich_project }}
immich_commands: -f {{ immich_compose_file }}
- "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" -f {{ immich_override_file }}
- "{{ 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"
# Commands to run on the target VM
immich_commands:
- "cd {{ immich_dir }}"
- |
cd {{ immich_dir }}
mkdir -p backups
if [ -f docker-compose.yml ]; then
cp -a docker-compose.yml "backups/docker-compose.yml.$(date +%F_%H%M%S).bak"
fi
if [ -f .env ]; then
cp -a .env "backups/.env.$(date +%F_%H%M%S).bak"
fi
if [ -f docker-compose.override.yml ]; then
cp -a docker-compose.override.yml "backups/docker-compose.override.yml.$(date +%F_%H%M%S).bak"
fi
- |
cd {{ immich_dir }}
# Download latest compose from Immich releases (requires curl or wget)
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o docker-compose.yml "{{ immich_compose_url }}"
elif command -v wget >/dev/null 2>&1; then
wget -qO docker-compose.yml "{{ immich_compose_url }}"
else
echo "Neither curl nor wget is available on the VM."
exit 1
fi
- |
cd {{ immich_dir }}
# Ensure override compose exists (create if missing)
if [ ! -f "{{ immich_override_file }}" ]; then
printf '%s\n' \
'services:' \
' immich-server:' \
' volumes:' \
' - /mnt/nextcloud-howard-photos:/mnt/nextcloud-howard-photos' \
' - /mnt/nextcloud-kamilkaprdelka-photos:/mnt/nextcloud-kamilkaprdelka-photos' \
> "{{ immich_override_file }}"
fi
# Fail early if override is still missing/empty
test -s "{{ immich_override_file }}"
- |
cd {{ immich_dir }}
# Ensure .env exists. If missing, try to reconstruct it from running containers to avoid breaking DB creds.
python3 - <<'PY'
import json
import subprocess
from pathlib import Path
env_path = Path(".env")
if env_path.exists():
raise SystemExit(0)
def run(cmd):
p = subprocess.run(cmd, capture_output=True, text=True)
return p.returncode, p.stdout, p.stderr
rc, out, err = run(["bash", "-lc", "command docker inspect immich_postgres immich_server"])
if rc != 0 or not out.strip():
print("ERROR: .env is missing and cannot inspect running containers (immich_postgres/immich_server).", flush=True)
print("Create /opt/immich/.env manually or ensure the containers exist.", flush=True)
raise SystemExit(1)
data = json.loads(out)
by_name = {}
for c in data:
name = (c.get("Name") or "").lstrip("/")
by_name[name] = c
pg = by_name.get("immich_postgres")
srv = by_name.get("immich_server")
if not pg or not srv:
print("ERROR: Could not find immich_postgres and immich_server in docker inspect output.", flush=True)
raise SystemExit(1)
def env_map(container):
m = {}
for kv in (container.get("Config", {}).get("Env") or []):
if "=" in kv:
k, v = kv.split("=", 1)
m[k] = v
return m
def find_mount_source(container, dest):
for m in (container.get("Mounts") or []):
if m.get("Destination") == dest:
return m.get("Source")
return ""
pg_env = env_map(pg)
db_user = pg_env.get("POSTGRES_USER", "")
db_pass = pg_env.get("POSTGRES_PASSWORD", "")
db_name = pg_env.get("POSTGRES_DB", "")
db_data = find_mount_source(pg, "/var/lib/postgresql/data")
upload_loc = find_mount_source(srv, "/usr/src/app/upload")
# Try to preserve the currently used image tag as IMMICH_VERSION (optional but safer)
immich_version = ""
image = (srv.get("Config", {}).get("Image") or "")
if ":" in image and "@" not in image:
immich_version = image.rsplit(":", 1)[-1]
elif ":" in image and "@" in image:
# image like repo:tag@sha256:...
immich_version = image.split("@", 1)[0].rsplit(":", 1)[-1]
missing = []
for k, v in [
("DB_USERNAME", db_user),
("DB_PASSWORD", db_pass),
("DB_DATABASE_NAME", db_name),
("DB_DATA_LOCATION", db_data),
("UPLOAD_LOCATION", upload_loc),
]:
if not v:
missing.append(k)
if missing:
print("ERROR: Could not reconstruct these .env values from containers: " + ", ".join(missing), flush=True)
raise SystemExit(1)
lines = [
f"UPLOAD_LOCATION={upload_loc}",
f"DB_DATA_LOCATION={db_data}",
f"DB_USERNAME={db_user}",
f"DB_PASSWORD={db_pass}",
f"DB_DATABASE_NAME={db_name}",
]
if immich_version:
lines.append(f"IMMICH_VERSION={immich_version}")
env_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
print("Created .env from running containers.", flush=True)
PY
- |
cd {{ immich_dir }}
# Comment out healthcheck.start_interval if present (safe no-op if missing)
sed -i -E 's/^([[:space:]]*)start_interval:/\1# start_interval:/' docker-compose.yml || true
- "cd {{ immich_dir }} && {{ immich_compose_cmd }} config >/dev/null"
- "cd {{ immich_dir }} && {{ immich_compose_cmd }} pull >/dev/null"
- "cd {{ immich_dir }} && {{ immich_compose_cmd }} up -d --remove-orphans --force-recreate >/dev/null"
tasks: tasks:
- name: Ensure sshpass is installed (for password-based SSH) # English comments - name: Ensure sshpass is installed (for password-based SSH) # English comments
@@ -57,8 +199,7 @@
state: present state: present
update_cache: yes update_cache: yes
- name: Run Immich update commands on VM (via SSH) # use SSHPASS env, hide item label
- name: Immich | Check compose directory exists on VM
ansible.builtin.command: ansible.builtin.command:
argv: argv:
- sshpass - sshpass
@@ -71,37 +212,17 @@
- "{{ vm_user }}@{{ vm_ip }}" - "{{ vm_user }}@{{ vm_ip }}"
- bash - bash
- -lc - -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 }}" - "{{ ('sudo ' if use_sudo else '') + item }}"
environment: environment:
SSHPASS: "{{ vm_pass }}" # supply password via environment SSHPASS: "{{ vm_pass }}"
loop: "{{ immich_commands }}" loop: "{{ immich_commands }}"
loop_control: loop_control:
index_var: idx # capture loop index index_var: idx
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line label: "cmd-{{ idx }}"
register: immich_cmds register: immich_cmds
changed_when: false changed_when: false
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging no_log: "{{ DEBUG == 0 }}"
run_once: true
- name: Show outputs for each Immich command - name: Show outputs for each Immich command
ansible.builtin.debug: ansible.builtin.debug:
@@ -114,8 +235,9 @@
{{ (item.stderr | default('')).strip() }} {{ (item.stderr | default('')).strip() }}
loop: "{{ immich_cmds.results }}" loop: "{{ immich_cmds.results }}"
when: DEBUG == 1 when: DEBUG == 1
run_once: true
- name: Fail play if any Immich command failed # also hide item label - name: Fail play if any Immich command failed
ansible.builtin.assert: ansible.builtin.assert:
that: "item.rc == 0" that: "item.rc == 0"
fail_msg: "Immich update failed on VM: {{ item.item }} (rc={{ item.rc }})" fail_msg: "Immich update failed on VM: {{ item.item }} (rc={{ item.rc }})"
@@ -124,17 +246,17 @@
loop_control: loop_control:
index_var: idx index_var: idx
label: "cmd-{{ idx }}" label: "cmd-{{ idx }}"
run_once: true
# ------------------------- # -------------------------
# Readiness checks (controller first, then VM fallback) # Readiness checks (controller first, then VM fallback)
# ------------------------- # -------------------------
- name: Immich | Wait for web UI (controller first, with retries) - name: Immich | Wait for API ping (controller first, with retries)
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ (immich_url | regex_replace('/$','')) + '/' }}" url: "{{ (immich_url | regex_replace('/$','')) + '/api/server/ping' }}"
method: GET method: GET
return_content: true return_content: true
# Validate TLS only when using https://
validate_certs: "{{ (immich_url | default('')) is match('^https://') }}" validate_certs: "{{ (immich_url | default('')) is match('^https://') }}"
status_code: 200 status_code: 200
register: immich_controller register: immich_controller
@@ -143,11 +265,11 @@
when: immich_url is defined and (immich_url | length) > 0 when: immich_url is defined and (immich_url | length) > 0
retries: "{{ immich_retries }}" retries: "{{ immich_retries }}"
delay: "{{ immich_delay }}" delay: "{{ immich_delay }}"
until: immich_controller.status == 200 until: immich_controller.status == 200 and ('pong' in (immich_controller.content | default('')))
failed_when: false # allow task to finish without failing the play failed_when: false
changed_when: false changed_when: false
- name: Immich | VM-side fetch (HTML via Python, with retries) # use SSHPASS env here too - name: Immich | VM-side ping (JSON via Python, with retries)
ansible.builtin.command: ansible.builtin.command:
argv: argv:
- sshpass - sshpass
@@ -162,10 +284,10 @@
- -lc - -lc
- | - |
python3 - <<'PY' python3 - <<'PY'
# Fetch Immich web UI from localhost and print HTML to stdout # Ping Immich API from localhost and print response to stdout
import urllib.request, sys import urllib.request, sys
try: try:
with urllib.request.urlopen("http://127.0.0.1:{{ immich_port }}/", timeout=15) as r: with urllib.request.urlopen("http://127.0.0.1:{{ immich_port }}/api/server/ping", timeout=15) as r:
sys.stdout.write(r.read().decode(errors='ignore')) sys.stdout.write(r.read().decode(errors='ignore'))
except Exception: except Exception:
pass pass
@@ -175,62 +297,17 @@
register: immich_vm register: immich_vm
changed_when: false changed_when: false
failed_when: false failed_when: false
when: immich_controller.status | default(0) != 200 or immich_controller.content is not defined when: immich_controller.status | default(0) != 200
retries: "{{ immich_retries }}" retries: "{{ immich_retries }}"
delay: "{{ immich_delay }}" delay: "{{ immich_delay }}"
until: (immich_vm.stdout | default('') | trim | length) > 0 and ('Immich' in (immich_vm.stdout | default(''))) until: (immich_vm.stdout | default('') | trim | length) > 0 and ('pong' in (immich_vm.stdout | default('')))
no_log: "{{ DEBUG == 0 }}" no_log: "{{ DEBUG == 0 }}"
run_once: true
- name: Immich | Choose homepage HTML (controller wins, else VM) # safe guard against empty result
ansible.builtin.set_fact:
immich_home_html: >-
{{
(
immich_controller.content
if (immich_controller is defined)
and ((immich_controller.status|default(0))==200)
and (immich_controller.content is defined)
else
(immich_vm.stdout | default('') | trim)
)
}}
when:
- (immich_controller is defined and (immich_controller.status|default(0))==200 and (immich_controller.content is defined))
or ((immich_vm.stdout | default('') | trim | length) > 0)
- name: Immich | Print concise summary - name: Immich | Print concise summary
ansible.builtin.debug: ansible.builtin.debug:
msg: >- msg: >-
Immich web UI {{ 'reachable' if (immich_home_html is defined) else 'NOT reachable' }}. Immich API ping {{ 'OK' if (('pong' in (immich_controller.content|default(''))) or ('pong' in (immich_vm.stdout|default('')))) else 'NOT OK' }}.
Source={{ 'controller' if ((immich_controller is defined) and (immich_controller.status|default(0))==200 and (immich_controller.content is defined)) else 'vm' if (immich_vm.stdout|default('')|trim|length>0) else 'n/a' }}; Source={{ 'controller' if (immich_controller.status|default(0))==200 else 'vm' if (immich_vm.stdout|default('')|trim|length>0) else 'n/a' }}.
length={{ (immich_home_html | default('')) | length }};
contains('Immich')={{ (immich_home_html is defined) and ('Immich' in immich_home_html) }}
when: DEBUG == 1 when: DEBUG == 1
run_once: true
- name: Immich | Web UI unavailable (after retries)
ansible.builtin.debug:
msg: "Immich web není dostupný ani po pokusech."
when: immich_home_html is not defined and DEBUG == 1
# Optional detailed dump (short excerpt only)
- name: Immich | HTML excerpt (debug)
ansible.builtin.debug:
msg: "{{ (immich_home_html | default(''))[:500] }}"
when: immich_home_html is defined and DEBUG == 1
# -------------------------
# Final assertion: controller URL must be reachable
# -------------------------
- name: Immich | Assert controller URL reachable (if configured)
ansible.builtin.assert:
that:
- >
not (immich_url is defined and (immich_url | length) > 0)
or
(
immich_controller is defined
and (immich_controller.status | default(0)) == 200
)
fail_msg: "Immich controller URL {{ immich_url }} is NOT reachable with HTTP 200 after retries."
success_msg: "Immich controller URL {{ immich_url }} is reachable with HTTP 200."

217
update_immich_old.yml Normal file
View File

@@ -0,0 +1,217 @@
# update_immich.yml
- name: Update Immich on VM via Proxmox
hosts: linux_servers
gather_facts: false
become: true
become_user: root
become_method: sudo
vars:
# --- Connection to VM (provided by Semaphore env vars) ---
vm_ip: "{{ lookup('env', 'VM_IP') }}"
vm_user: "{{ lookup('env', 'VM_USER') }}"
vm_pass: "{{ lookup('env', 'VM_PASS') }}"
use_sudo: false
# --- Debug mode (controlled via Semaphore variable) ---
DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}"
RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}"
# --- Immich specifics ---
immich_project: "immich"
# Where compose file lives on the VM
immich_compose_dir: "/opt/immich"
immich_compose_file: "{{ immich_compose_dir }}/docker-compose.yml"
# Official Immich compose URL (latest release)
immich_compose_url: "https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml"
immich_port: 2283
# Optional external URL for controller-side readiness check
# Default to https://photos.martinfencl.eu/photos if IMMICH_URL is not set
immich_url: "{{ lookup('env', 'IMMICH_URL') | default('https://photos.martinfencl.eu/photos', true) }}"
immich_retries: "{{ RETRIES }}"
immich_delay: 2
# 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
# 3) Start / update stack
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 --force-recreate >/dev/null"
# - "{{ docker_prefix }} compose -p {{ immich_project }} -f {{ immich_compose_file }} up -d --remove-orphans >/dev/null"
tasks:
- name: Ensure sshpass is installed (for password-based SSH) # English comments
ansible.builtin.apt:
name: sshpass
state: present
update_cache: yes
- name: Run Immich update commands on VM (via SSH) # use SSHPASS env, hide item value
ansible.builtin.command:
argv:
- sshpass
- -e
- ssh
- -o
- StrictHostKeyChecking=no
- -o
- ConnectTimeout=15
- "{{ vm_user }}@{{ vm_ip }}"
- bash
- -lc
- "{{ ('sudo ' if use_sudo else '') + item }}"
environment:
SSHPASS: "{{ vm_pass }}"
loop: "{{ immich_commands }}"
loop_control:
index_var: idx
label: "cmd-{{ idx }}"
register: immich_cmds
changed_when: false
no_log: "{{ DEBUG == 0 }}"
run_once: true # <<< přidat
- name: Show outputs for each Immich command
ansible.builtin.debug:
msg: |
CMD: {{ item.item }}
RC: {{ item.rc }}
STDOUT:
{{ (item.stdout | default('')).strip() }}
STDERR:
{{ (item.stderr | default('')).strip() }}
loop: "{{ immich_cmds.results }}"
when: DEBUG == 1
- 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 }})"
success_msg: "All Immich update commands succeeded."
loop: "{{ immich_cmds.results }}"
loop_control:
index_var: idx
label: "cmd-{{ idx }}"
run_once: true
# -------------------------
# Readiness checks (controller first, then VM fallback)
# -------------------------
- name: Immich | Wait for web UI (controller first, with retries)
ansible.builtin.uri:
url: "{{ (immich_url | regex_replace('/$','')) + '/' }}"
method: GET
return_content: true
# Validate TLS only when using https://
validate_certs: "{{ (immich_url | default('')) is match('^https://') }}"
status_code: 200
register: immich_controller
delegate_to: localhost
run_once: true
when: immich_url is defined and (immich_url | length) > 0
retries: "{{ immich_retries }}"
delay: "{{ immich_delay }}"
until: immich_controller.status == 200
failed_when: false # allow task to finish without failing the play
changed_when: false
- name: Immich | VM-side fetch (HTML via Python, with retries) # use SSHPASS env here too
ansible.builtin.command:
argv:
- sshpass
- -e
- ssh
- -o
- StrictHostKeyChecking=no
- -o
- ConnectTimeout=15
- "{{ vm_user }}@{{ vm_ip }}"
- bash
- -lc
- |
python3 - <<'PY'
# Fetch Immich web UI from localhost and print HTML to stdout
import urllib.request, sys
try:
with urllib.request.urlopen("http://127.0.0.1:{{ immich_port }}/", timeout=15) as r:
sys.stdout.write(r.read().decode(errors='ignore'))
except Exception:
pass
PY
environment:
SSHPASS: "{{ vm_pass }}"
register: immich_vm
changed_when: false
failed_when: false
when: immich_controller.status | default(0) != 200 or immich_controller.content is not defined
retries: "{{ immich_retries }}"
delay: "{{ immich_delay }}"
until: (immich_vm.stdout | default('') | trim | length) > 0 and ('Immich' in (immich_vm.stdout | default('')))
no_log: "{{ DEBUG == 0 }}"
- name: Immich | Choose homepage HTML (controller wins, else VM) # safe guard against empty result
ansible.builtin.set_fact:
immich_home_html: >-
{{
(
immich_controller.content
if (immich_controller is defined)
and ((immich_controller.status|default(0))==200)
and (immich_controller.content is defined)
else
(immich_vm.stdout | default('') | trim)
)
}}
when:
- (immich_controller is defined and (immich_controller.status|default(0))==200 and (immich_controller.content is defined))
or ((immich_vm.stdout | default('') | trim | length) > 0)
- name: Immich | Print concise summary
ansible.builtin.debug:
msg: >-
Immich web UI {{ 'reachable' if (immich_home_html is defined) else 'NOT reachable' }}.
Source={{ 'controller' if ((immich_controller is defined) and (immich_controller.status|default(0))==200 and (immich_controller.content is defined)) else 'vm' if (immich_vm.stdout|default('')|trim|length>0) else 'n/a' }};
length={{ (immich_home_html | default('')) | length }};
contains('Immich')={{ (immich_home_html is defined) and ('Immich' in immich_home_html) }}
when: DEBUG == 1
- name: Immich | Web UI unavailable (after retries)
ansible.builtin.debug:
msg: "Immich web není dostupný ani po pokusech."
when: immich_home_html is not defined and DEBUG == 1
# Optional detailed dump (short excerpt only)
- name: Immich | HTML excerpt (debug)
ansible.builtin.debug:
msg: "{{ (immich_home_html | default(''))[:500] }}"
when: immich_home_html is defined and DEBUG == 1
# -------------------------
# Final assertion: controller URL must be reachable
# -------------------------
- name: Immich | Assert controller URL reachable (if configured)
ansible.builtin.assert:
that:
- >
not (immich_url is defined and (immich_url | length) > 0)
or
(
immich_controller is defined
and (immich_controller.status | default(0)) == 200
)
fail_msg: "Immich controller URL {{ immich_url }} is NOT reachable with HTTP 200 after retries."
success_msg: "Immich controller URL {{ immich_url }} is reachable with HTTP 200."