diff --git a/defaults/main.yml b/defaults/main.yml index 1003a31..4bf836c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,3 +14,18 @@ jellyfin_dependencies: - krb5-libs - libicu - zlib + +# Create separate LVM storage for jellyfin +jellyfin_lvm_enabled: False +# This variables are only necessary if jellyfin_lvm_enabled is 'True' +# Set physical volumes to use in LVM +# jellyfin_lvm_pvs: # ['/dev/sdb', '/dev/sdc'] +# jellyfin_lvm_vg: # "vg_jellyfin" +# jellyfin_lvm_lv: # "lv_jellyfin" +# jellyfin_lvm_fstype: # ext4 +# jellyfin_lvm_size: # "50G" + +jellyfin_base_dir: "/opt/jellyfin" +jellyfin_conf_dir: "{{ jellyfin_base_dir }}/config" +jellyfin_data_dir: "{{ jellyfin_base_dir }}/data" +jellyfin_log_dir: "{{ jellyfin_base_dir }}/log" diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..140ee15 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,66 @@ +--- +- name: Prepare base folders + file: + path: "{{ item }}" + state: directory + owner: "{{ jellyfin_user }}" + group: "{{ jellyfin_user }}" + mode: 0750 + loop: + - "{{ jellyfin_base_dir }}" + - "{{ jellyfin_base_dir }}/{{ jellyfin_version }}" + - "{{ jellyfin_conf_dir }}" + - "{{ jellyfin_data_dir }}" + - "{{ jellyfin_log_dir }}" + become: True + become_user: root + +- block: + - name: Install portable binary + unarchive: + src: https://repo.jellyfin.org/releases/server/linux/jellyfin_{{ jellyfin_version }}.portable-linux-amd64.tar.gz + dest: "{{ jellyfin_base_dir }}/{{ jellyfin_version }}" + extra_opts: + - --strip-components=1 + remote_src: yes + + - name: Deploy global config files + template: + src: "opt/jellyfin/config/{{ item }}.j2" + dest: "{{ jellyfin_conf_dir }}/{{ item }}" + mode: 0600 + loop: + - "logging.json" + # notify: __jellyfin_restart + become: True + become_user: "{{ jellyfin_user }}" + +# - block: +# - name: Copy systemd unit file +# template: +# src: "etc/systemd/system/jellyfin.service.j2" +# dest: "/etc/systemd/system/jellyfin.service" +# notify: __jellyfin_restart + +# - name: Copy logrotate config +# template: +# src: "etc/logrotate.d/config.j2" +# dest: "/etc/logrotate.d/jellyfin" +# loop: "{{ jellyfin_logrotate_config }}" +# loop_control: +# label: "{{ item.log }}" +# when: jellyfin_logrotate_enabled + +# - name: Open ports in iptables +# iptables_raw: +# name: "{{ item.name }}" +# rules: "{{ item.rules }}" +# state: "{{ item.state }}" +# weight: "{{ item.weight | default(omit) }}" +# table: "{{ item.table | default(omit) }}" +# loop: "{{ jellyfin_open_ports }}" +# loop_control: +# label: "{{ item.name }}" +# when: jellyfin_iptables_enabled +# become: True +# become_user: root diff --git a/tasks/main.yml b/tasks/main.yml index 47bb8b2..a08513e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,5 @@ --- - include_tasks: prepare.yml +- import_tasks: storage.yml + when: jellyfin_lvm_enabled +- include_tasks: install.yml diff --git a/tasks/storage.yml b/tasks/storage.yml new file mode 100644 index 0000000..09cf7c5 --- /dev/null +++ b/tasks/storage.yml @@ -0,0 +1,27 @@ +--- +- block: + - name: Create volume group '{{ jellyfin_lvm_vg }}' + lvg: + vg: "{{ jellyfin_lvm_vg }}" + pvs: "{{ jellyfin_lvm_pvs | join(',') }}" + + - name: Create logical volume '{{ jellyfin_lvm_lv }}' + lvol: + vg: "{{ jellyfin_lvm_vg }}" + lv: "{{ jellyfin_lvm_lv }}" + size: "{{ jellyfin_lvm_size }}" + + - name: Create filesystem for '/dev/mapper/{{ jellyfin_lvm_vg }}-{{ jellyfin_lvm_lv }}' + filesystem: + fstype: "{{ jellyfin_lvm_fstype }}" + dev: "/dev/mapper/{{ jellyfin_lvm_vg }}-{{ jellyfin_lvm_lv }}" + resizefs: True + + - name: Mount volume to '{{ jellyfin_base_dir }}' + mount: + path: "{{ jellyfin_base_dir }}" + src: "/dev/mapper/{{ jellyfin_lvm_vg }}-{{ jellyfin_lvm_lv }}" + fstype: "{{ jellyfin_lvm_fstype }}" + state: mounted + become: True + become_user: root diff --git a/templates/opt/jellyfin/config/logging.json.j2 b/templates/opt/jellyfin/config/logging.json.j2 new file mode 100644 index 0000000..389a7ed --- /dev/null +++ b/templates/opt/jellyfin/config/logging.json.j2 @@ -0,0 +1,30 @@ +{ + "Serilog": { + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "Console", + "Args": { + "outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "Async", + "Args": { + "configure": [ + { + "Name": "File", + "Args": { + "path": "{{ jellyfin_log_dir }}/jellyfin.log", + "fileSizeLimitBytes": 10485700, + "rollOnFileSizeLimit": true, + "retainedFileCountLimit": 10, + "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}" + } + } + ] + } + } + ] + } +}