---

# https://jellyfin.org/downloads/server

- name: add jellyfin apt key
  become: yes
  get_url:
    url: "https://repo.jellyfin.org/jellyfin_team.gpg.key"
    dest: "/etc/apt/trusted.gpg.d/jellyfin_team.asc"
    mode: "0644"

- name: add jellyfin apt repo
  become: yes
  apt_repository: repo="deb [signed-by=/etc/apt/trusted.gpg.d/jellyfin_team.asc] https://repo.jellyfin.org/ubuntu noble main unstable"
  notify: restart jellyfin service

- name: update apt package cache
  become: yes
  apt: upgrade="dist" update_cache="yes" cache_valid_time="3600"

- name: install jellyfin server
  become: yes
  apt: name="jellyfin"
  notify: restart jellyfin service

- name: create jellyfin data dir
  become: yes
  file:
    path: "{{jellyfin_data_dir}}"
    state: "directory"
    owner: "jellyfin"
    group: "jellyfin"
    mode: "0755"

- name: configure jellyfin data dir
  become: yes
  lineinfile:
    path: "/etc/jellyfin/jellyfin"
    regexp: "^JELLYFIN_DATA_DIR="
    line: "JELLYFIN_DATA_DIR={{jellyfin_data_dir}}"
    create: yes
  notify: restart jellyfin service

- name: ensure jellyfin service is running
  become: yes
  systemd: name="jellyfin.service" state="started" daemon_reload="yes"
