Files
ansible/update_immich.yml
martin.fencl 325cc99c09 .
2026-02-03 18:51:53 +01:00

116 lines
3.5 KiB
YAML

# update_immich.yml
- name: Update Immich
hosts: pve2_vm
gather_facts: false
vars:
# Compose sync (controller -> target)
compose_local_dir: "{{ playbook_dir }}/docker-compose"
compose_remote_base: "/home/{{ ansible_user }}/.ansible-compose"
compose_remote_dir: "{{ compose_remote_base }}/docker-compose"
compose_remote_archive: "{{ compose_remote_base }}/docker-compose.tar.gz"
# Immich settings
immich_project: immich
immich_port: 2283
immich_compose_files:
- docker-compose-immich.yml
- docker-compose-immich.override.yml
# Persistent env file on the VM (NOT in git)
immich_env_persistent: "{{ compose_remote_base }}/env/immich.env"
tasks:
- name: Ensure remote base directory exists
ansible.builtin.file:
path: "{{ compose_remote_base }}"
state: directory
mode: "0755"
- name: Ensure remote env directory exists
ansible.builtin.file:
path: "{{ compose_remote_base }}/env"
state: directory
- name: Fail if persistent Immich env file is missing
ansible.builtin.stat:
path: "{{ immich_env_persistent }}"
register: immich_env_stat
- name: Abort when Immich env is missing
ansible.builtin.fail:
msg: >-
Missing persistent env file: {{ immich_env_persistent }}.
Create it on the VM with DB_* and UPLOAD_LOCATION variables.
when: not immich_env_stat.stat.exists
- name: Create local archive of docker-compose directory (controller)
ansible.builtin.archive:
path: "{{ compose_local_dir }}/"
dest: "/tmp/docker-compose.tar.gz"
format: gz
delegate_to: localhost
run_once: true
- name: Upload archive to remote host
ansible.builtin.copy:
src: "/tmp/docker-compose.tar.gz"
dest: "{{ compose_remote_archive }}"
mode: "0644"
- name: Recreate remote compose directory
ansible.builtin.file:
path: "{{ compose_remote_dir }}"
state: absent
- name: Ensure remote compose directory exists
ansible.builtin.file:
path: "{{ compose_remote_dir }}"
state: directory
mode: "0755"
- name: Extract archive on remote host
ansible.builtin.unarchive:
src: "{{ compose_remote_archive }}"
dest: "{{ compose_remote_dir }}"
remote_src: true
- name: Deploy Immich .env into compose directory
ansible.builtin.copy:
src: "{{ immich_env_persistent }}"
dest: "{{ compose_remote_dir }}/.env"
remote_src: true
mode: "0600"
- name: Pull latest Immich images
community.docker.docker_compose_v2:
project_name: "{{ immich_project }}"
project_src: "{{ compose_remote_dir }}"
files: "{{ immich_compose_files }}"
pull: always
- name: Recreate Immich stack
community.docker.docker_compose_v2:
project_name: "{{ immich_project }}"
project_src: "{{ compose_remote_dir }}"
files: "{{ immich_compose_files }}"
state: present
recreate: always
- name: Wait for Immich port
ansible.builtin.wait_for:
host: 127.0.0.1
port: "{{ immich_port }}"
timeout: 120
- name: Check Immich API ping (retry until ready)
ansible.builtin.uri:
url: "http://127.0.0.1:{{ immich_port }}/api/server/ping"
status_code: 200
return_content: true
register: immich_ping
retries: 40
delay: 3
until: immich_ping.status == 200 and ('pong' in (immich_ping.content | default('')))
changed_when: false