ansible-nas/roles/plex/tasks/main.yml

52 lines
2.1 KiB
YAML

---
- name: Start Plex
block:
- name: Create Plex Directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
# mode: 0755
with_items:
- "{{ plex_config_directory }}"
- "{{ plex_logs }}"
- name: Create Plex Docker Container
community.docker.docker_container:
container_default_behavior: no_defaults
name: "{{ plex_container_name }}"
image: "{{ plex_image_name }}:{{ plex_image_version }}"
pull: true
volumes:
- "{{ plex_config_directory }}:/config:rw"
- "{{ plex_logs }}:/opt/plex/Library/Application Support/Plex Media Server/Logs:rw"
- "{{ plex_movies_directory }}:/movies:{{ plex_movies_permissions }}"
- "{{ plex_tv_directory }}:/tv:{{ plex_tv_permissions }}"
- "{{ plex_photos_directory }}:/photos:{{ plex_photos_permissions }}"
- "{{ plex_podcasts_directory }}:/podcasts:{{ plex_podcasts_permissions }}"
- "{{ plex_music_directory }}:/music:{{ plex_music_permissions }}"
- "{{ plex_audiobooks_directory }}:/audiobooks:{{ plex_audiobooks_permissions }}"
network_mode: "host"
devices: "{{ plex_devices | default(omit) }}"
env:
TZ: "{{ ansible_nas_timezone }}"
PUID: "{{ plex_user_id }}"
PGID: "{{ plex_group_id }}"
VERSION: "{{ plex_version }}"
restart_policy: unless-stopped
memory: "{{ plex_memory }}"
labels:
traefik.enable: "{{ plex_available_externally | string }}"
traefik.http.routers.plex.rule: "Host(`{{ plex_hostname }}.{{ ansible_nas_domain }}`)"
traefik.http.routers.plex.tls.certresolver: "letsencrypt"
traefik.http.routers.plex.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.plex.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.plex.loadbalancer.server.port: "32400"
when: plex_enabled is true
- name: Stop Plex
block:
- name: Stop Plex
community.docker.docker_container:
name: "{{ plex_container_name }}"
state: absent
when: plex_enabled is false