This commit is contained in:
2025-12-29 19:11:06 +01:00
parent 27bbd9621a
commit b902142c4b
10 changed files with 216 additions and 0 deletions

29
defaults/main.yml Normal file
View File

@@ -0,0 +1,29 @@
immich_image_tag: "release"
immich_server_image: "ghcr.io/immich-app/immich-server:{{ immich_image_tag }}"
immich_microservices_image: "ghcr.io/immich-app/immich-server:{{ immich_image_tag }}"
immich_ml_image: "ghcr.io/immich-app/immich-machine-learning:{{ immich_image_tag }}"
immich_postgres_image: "postgres:14"
immich_redis_image: "redis:6"
immich_network_name: "immich"
immich_upload_location: "/opt/immich/library"
immich_db_data_location: "/opt/immich/postgres"
immich_redis_data_location: "/opt/immich/redis"
immich_model_cache_dir: "/opt/immich/ml-cache"
immich_env_path: "/etc/immich/immich.env"
immich_postgres_env_path: "/etc/immich/postgres.env"
immich_timezone: "UTC"
immich_db_user: "immich"
immich_db_password: "immich_password_change_me"
immich_db_name: "immich"
immich_server_port: 2283
immich_container_uid: 1000
immich_container_gid: 1000
immich_machine_learning_enabled: true

3
handlers/main.yml Normal file
View File

@@ -0,0 +1,3 @@
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true

77
tasks/main.yml Normal file
View File

@@ -0,0 +1,77 @@
- name: Install Podman packages
ansible.builtin.apt:
name:
- podman
- uidmap
- slirp4netns
- fuse-overlayfs
state: present
update_cache: true
- name: Create Immich config directory
ansible.builtin.file:
path: /etc/immich
state: directory
mode: "0750"
- name: Create Immich data directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ immich_container_uid }}"
group: "{{ immich_container_gid }}"
mode: "0750"
loop:
- "{{ immich_upload_location }}"
- "{{ immich_db_data_location }}"
- "{{ immich_redis_data_location }}"
- "{{ immich_model_cache_dir }}"
- name: Write Immich env file
ansible.builtin.template:
src: immich.env.j2
dest: "{{ immich_env_path }}"
mode: "0640"
- name: Write Postgres env file
ansible.builtin.template:
src: postgres.env.j2
dest: "{{ immich_postgres_env_path }}"
mode: "0640"
- name: Check Immich podman network
ansible.builtin.command: "podman network exists {{ immich_network_name }}"
register: immich_network_check
changed_when: false
failed_when: false
- name: Create Immich podman network
ansible.builtin.command: "podman network create {{ immich_network_name }}"
when: immich_network_check.rc != 0
- name: Install systemd unit files
ansible.builtin.template:
src: "{{ item.src }}"
dest: "/etc/systemd/system/{{ item.dest }}"
mode: "0644"
loop:
- { src: immich-redis.service.j2, dest: immich-redis.service }
- { src: immich-postgres.service.j2, dest: immich-postgres.service }
- { src: immich-server.service.j2, dest: immich-server.service }
- { src: immich-microservices.service.j2, dest: immich-microservices.service }
- { src: immich-machine-learning.service.j2, dest: immich-machine-learning.service }
when: item.dest != 'immich-machine-learning.service' or immich_machine_learning_enabled
notify: Reload systemd
- name: Enable and start Immich services
ansible.builtin.systemd:
name: "{{ item }}"
enabled: true
state: started
loop:
- immich-redis.service
- immich-postgres.service
- immich-server.service
- immich-microservices.service
- immich-machine-learning.service
when: item != 'immich-machine-learning.service' or immich_machine_learning_enabled

View File

@@ -0,0 +1,18 @@
[Unit]
Description=Immich Machine Learning Container
After=network-online.target
Wants=network-online.target
[Service]
Restart=always
ExecStart=/usr/bin/podman run --rm --name immich-machine-learning \
--network {{ immich_network_name }} \
--user {{ immich_container_uid }}:{{ immich_container_gid }} \
-v {{ immich_model_cache_dir }}:/cache:Z \
{{ immich_ml_image }}
ExecStop=/usr/bin/podman stop -t 10 immich-machine-learning
ExecStopPost=/usr/bin/podman rm -f immich-machine-learning
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,20 @@
[Unit]
Description=Immich Microservices Container
After=network-online.target immich-redis.service immich-postgres.service
Wants=network-online.target
Requires=immich-redis.service immich-postgres.service
[Service]
Restart=always
ExecStart=/usr/bin/podman run --rm --name immich-microservices \
--network {{ immich_network_name }} \
--env-file {{ immich_env_path }} \
--user {{ immich_container_uid }}:{{ immich_container_gid }} \
-v {{ immich_upload_location }}:/usr/src/app/upload:Z \
{{ immich_microservices_image }}
ExecStop=/usr/bin/podman stop -t 10 immich-microservices
ExecStopPost=/usr/bin/podman rm -f immich-microservices
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
[Unit]
Description=Immich Postgres Container
After=network-online.target
Wants=network-online.target
[Service]
Restart=always
ExecStart=/usr/bin/podman run --rm --name immich-postgres \
--network {{ immich_network_name }} \
--env-file {{ immich_postgres_env_path }} \
-v {{ immich_db_data_location }}:/var/lib/postgresql/data:Z \
{{ immich_postgres_image }}
ExecStop=/usr/bin/podman stop -t 10 immich-postgres
ExecStopPost=/usr/bin/podman rm -f immich-postgres
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,17 @@
[Unit]
Description=Immich Redis Container
After=network-online.target
Wants=network-online.target
[Service]
Restart=always
ExecStart=/usr/bin/podman run --rm --name immich-redis \
--network {{ immich_network_name }} \
-v {{ immich_redis_data_location }}:/data:Z \
{{ immich_redis_image }}
ExecStop=/usr/bin/podman stop -t 10 immich-redis
ExecStopPost=/usr/bin/podman rm -f immich-redis
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,21 @@
[Unit]
Description=Immich Server Container
After=network-online.target immich-redis.service immich-postgres.service
Wants=network-online.target
Requires=immich-redis.service immich-postgres.service
[Service]
Restart=always
ExecStart=/usr/bin/podman run --rm --name immich-server \
--network {{ immich_network_name }} \
-p {{ immich_server_port }}:3001 \
--env-file {{ immich_env_path }} \
--user {{ immich_container_uid }}:{{ immich_container_gid }} \
-v {{ immich_upload_location }}:/usr/src/app/upload:Z \
{{ immich_server_image }}
ExecStop=/usr/bin/podman stop -t 10 immich-server
ExecStopPost=/usr/bin/podman rm -f immich-server
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

10
templates/immich.env.j2 Normal file
View File

@@ -0,0 +1,10 @@
TZ={{ immich_timezone }}
DB_HOSTNAME=immich-postgres
DB_PORT=5432
DB_USERNAME={{ immich_db_user }}
DB_PASSWORD={{ immich_db_password }}
DB_DATABASE_NAME={{ immich_db_name }}
REDIS_HOSTNAME=immich-redis
{% if immich_machine_learning_enabled %}
IMMICH_MACHINE_LEARNING_URL=http://immich-machine-learning:3003
{% endif %}

View File

@@ -0,0 +1,3 @@
POSTGRES_USER={{ immich_db_user }}
POSTGRES_PASSWORD={{ immich_db_password }}
POSTGRES_DB={{ immich_db_name }}