From ddebf0618cf11d627540497f241ca5b5acc12505 Mon Sep 17 00:00:00 2001 From: Johanna Dorothea Reichmann Date: Thu, 17 Mar 2022 15:12:56 +0100 Subject: [PATCH] feat(jellyfin): add role for ansible deployment in docker container --- README.md | 3 +++ roles/jellyfin/defaults/main.yml | 29 ++++++++++++++++++++++++++ roles/jellyfin/tasks/main.yml | 35 ++++++++++++++++++++++++++++++++ roles/jellyfin/vars/main.yml | 5 +++++ 4 files changed, 72 insertions(+) create mode 100644 roles/jellyfin/defaults/main.yml create mode 100644 roles/jellyfin/tasks/main.yml create mode 100644 roles/jellyfin/vars/main.yml diff --git a/README.md b/README.md index 19fc688..55be81a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ concise area of concern. - [`roles/gitea`](roles/gitea/README.md): Deploy [gitea.io](https://gitea.io), a lightweight, self-hosted git service. +- [`roles/jellyfin`](roles/jellyfin/README.md): Deploy [jellyfin.org](https://jellyfin.org), + the free software media system for streaming stored media to any device. + - [`roles/restic`](roles/restic/README.md): Manage backups using restic and persist them to a configurable backend. diff --git a/roles/jellyfin/defaults/main.yml b/roles/jellyfin/defaults/main.yml new file mode 100644 index 0000000..78c1a3c --- /dev/null +++ b/roles/jellyfin/defaults/main.yml @@ -0,0 +1,29 @@ +--- + +jellyfin_user: jellyfin + +jellyfin_base_path: /opt/jellyfin +jellyfin_config_path: "{{ jellyfin_base_path }}/config" +jellyfin_cache_path: "{{ jellyfin_base_path }}/cache" + +jellyfin_media_volumes: [] + +jellyfin_container_name: jellyfin +jellyfin_container_image_name: "docker.io/jellyfin/jellyfin" +jellyfin_container_image_tag: "latest" +jellyfin_container_image_ref: "{{ jellyfin_container_image_name }}:{{ jellyfin_container_image_tag }}" +jellyfin_container_network_mode: host +jellyfin_container_networks: ~ +jellyfin_container_volumes: "{{ jellyfin_container_base_volumes + jellyfin_media_volumes }}" +jellyfin_container_restart_policy: "unless-stopped" + +jellyfin_host_directories: + - path: "{{ jellyfin_base_path }}" + mode: "0750" + - path: "{{ jellyfin_config_path }}" + mode: "0750" + - path: "{{ jellyfin_cache_path }}" + mode: "0750" + +jellyfin_uid: "{{ jellyfin_user_info.uid | default(jellyfin_user) }}" +jellyfin_gid: "{{ jellyfin_user_info.group | default(jellyfin_user) }}" diff --git a/roles/jellyfin/tasks/main.yml b/roles/jellyfin/tasks/main.yml new file mode 100644 index 0000000..14a8256 --- /dev/null +++ b/roles/jellyfin/tasks/main.yml @@ -0,0 +1,35 @@ +--- + +- name: Ensure user '{{ jellyfin_user }}' for jellyfin is created + user: + name: "{{ jellyfin_user }}" + state: present + system: yes + register: jellyfin_user_info + +- name: Ensure host directories for jellyfin exist + file: + path: "{{ item.path }}" + state: directory + owner: "{{ item.owner | default(jellyfin_uid) }}" + group: "{{ item.group | default(jellyfin_gid) }}" + mode: "{{ item.mode }}" + loop: "{{ jellyfin_host_directories }}" + +- name: Ensure container image for jellyfin is available + docker_image: + name: "{{ jellyfin_container_image_ref }}" + state: present + source: pull + force_source: "{{ jellyfin_container_image_tag in ['stable', 'unstable'] }}" + +- name: Ensure container '{{ jellyfin_container_name }}' is running + docker_container: + name: "{{ jellyfin_container_name }}" + image: "{{ jellyfin_container_image_ref }}" + user: "{{ jellyfin_uid }}:{{ jellyfin_gid }}" + volumes: "{{ jellyfin_container_volumes }}" + networks: "{{ jellyfin_container_networks | default(omit, True) }}" + network_mode: "{{ jellyfin_container_network_mode }}" + restart_policy: "{{ jellyfin_container_restart_policy }}" + state: started diff --git a/roles/jellyfin/vars/main.yml b/roles/jellyfin/vars/main.yml new file mode 100644 index 0000000..d5e587b --- /dev/null +++ b/roles/jellyfin/vars/main.yml @@ -0,0 +1,5 @@ +--- + +jellyfin_container_base_volumes: + - "{{ jellyfin_config_path }}:/config:z" + - "{{ jellyfin_cache_path }}:/cache:z"