first version

This commit is contained in:
cpu
2024-01-31 14:28:36 +01:00
parent ffa90bce8b
commit 3f15c9e579
11 changed files with 358 additions and 1 deletions

43
tasks/install.yml Normal file
View File

@@ -0,0 +1,43 @@
---
- name: Ensure Immich paths exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0750"
owner: "{{ immich_uid }}"
group: "{{ immich_gid }}"
with_items:
- "{{ immich_base_path }}"
- "{{ immich_config_dir_path }}"
- "{{ immich_photos_dir_path }}"
- "{{ immich_import_dir_path }}"
- name: Ensure Immich support files created
ansible.builtin.template:
src: "{{ role_path }}/templates/{{ item }}.j2"
dest: "{{ immich_base_path }}/{{ item }}"
owner: "{{ immich_uid }}"
group: "{{ immich_gid }}"
mode: 0640
with_items:
- env
- labels
- name: Ensure Immich container network is created
community.general.docker_network:
name: "{{ immich_container_network }}"
driver: bridge
- name: Ensure Immich container image is pulled
community.docker.docker_image:
name: "{{ immich_container_image }}"
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
force_source: "{{ immich_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else immich_container_image_force_pull }}"
- name: Ensure Immich systemd service installed
ansible.builtin.template:
src: "{{ role_path }}/templates/immich.service.j2"
dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ immich_identifier }}.service"
mode: 0644

20
tasks/main.yml Normal file
View File

@@ -0,0 +1,20 @@
---
- block:
- when: immich_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
- when: immich_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/install.yml"
tags:
- setup-all
- setup-immich
- install-all
- install-immich
- block:
- when: not immich_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/uninstall.yml"
tags:
- setup-all
- setup-immich

25
tasks/uninstall.yml Normal file
View File

@@ -0,0 +1,25 @@
---
- name: Check existence of Immich systemd service
ansible.builtin.stat:
path: "{{ devture_systemd_docker_base_systemd_path }}/{{ immich_identifier }}.service"
register: immich_service_stat
- when: immich_service_stat.stat.exists | bool
block:
- name: Ensure Immich systemd service is stopped
ansible.builtin.service:
name: "{{ immich_identifier }}"
state: stopped
enabled: false
daemon_reload: true
- name: Ensure Immich systemd service does not exists
ansible.builtin.file:
path: "{{ devture_systemd_docker_base_systemd_path }}/{{ immich_identifier }}.service"
state: absent
- name: Ensure Immich path doesn't exist
ansible.builtin.file:
path: "{{ immich_base_path }}"
state: absent

38
tasks/validate_config.yml Normal file
View File

@@ -0,0 +1,38 @@
---
- name: Fail if required Immich settings not defined
ansible.builtin.fail:
msg: >-
You need to define a required configuration setting (`{{ item }}`) for using this role.
when: "vars[item] | string == ''"
with_items:
- immich_identifier
- immich_uid
- immich_gid
- immich_container_network
- immich_hostname
- immich_path_prefix
- immich_config_database_hostname
- immich_config_database_username
- immich_config_database_password
- immich_config_redis_hostname
- when: immich_container_labels_traefik_enabled | bool
block:
- name: Fail if required Immich Traefik settings not defined
ansible.builtin.fail:
msg: >-
You need to define a required configuration setting (`{{ item }}`).
when: "vars[item] == ''"
with_items:
- immich_container_labels_traefik_hostname
- immich_container_labels_traefik_path_prefix
# We ensure it doesn't end with a slash, because we handle both (slash and no-slash).
# Knowing that `immich_container_labels_traefik_path_prefix` does not end with a slash
# ensures we know how to set these routes up without having to do "does it end with a slash" checks elsewhere.
- name: Fail if immich_container_labels_traefik_path_prefix ends with a slash
ansible.builtin.fail:
msg: >-
immich_container_labels_traefik_path_prefix (`{{ immich_container_labels_traefik_path_prefix }}`) must either be `/` or not end with a slash (e.g. `/immich`).
when: "immich_container_labels_traefik_path_prefix != '/' and immich_container_labels_traefik_path_prefix[-1] == '/'"