diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..0d42fa6 --- /dev/null +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..57fcca9 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,3 @@ +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ff9bf24 --- /dev/null +++ b/tasks/main.yml @@ -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 diff --git a/templates/immich-machine-learning.service.j2 b/templates/immich-machine-learning.service.j2 new file mode 100644 index 0000000..11d949d --- /dev/null +++ b/templates/immich-machine-learning.service.j2 @@ -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 diff --git a/templates/immich-microservices.service.j2 b/templates/immich-microservices.service.j2 new file mode 100644 index 0000000..11f7f16 --- /dev/null +++ b/templates/immich-microservices.service.j2 @@ -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 diff --git a/templates/immich-postgres.service.j2 b/templates/immich-postgres.service.j2 new file mode 100644 index 0000000..6943f0b --- /dev/null +++ b/templates/immich-postgres.service.j2 @@ -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 diff --git a/templates/immich-redis.service.j2 b/templates/immich-redis.service.j2 new file mode 100644 index 0000000..c6dd080 --- /dev/null +++ b/templates/immich-redis.service.j2 @@ -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 diff --git a/templates/immich-server.service.j2 b/templates/immich-server.service.j2 new file mode 100644 index 0000000..5d2e938 --- /dev/null +++ b/templates/immich-server.service.j2 @@ -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 diff --git a/templates/immich.env.j2 b/templates/immich.env.j2 new file mode 100644 index 0000000..4d095b4 --- /dev/null +++ b/templates/immich.env.j2 @@ -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 %} diff --git a/templates/postgres.env.j2 b/templates/postgres.env.j2 new file mode 100644 index 0000000..1e496c5 --- /dev/null +++ b/templates/postgres.env.j2 @@ -0,0 +1,3 @@ +POSTGRES_USER={{ immich_db_user }} +POSTGRES_PASSWORD={{ immich_db_password }} +POSTGRES_DB={{ immich_db_name }}