---
- name: PyTivo - create config directory
  file:
    path: "{{ item }}"
    state: directory
    mode: 0777
  with_items:
    - "{{ pytivo_config_directory }}"

- name: PyTivo - install Docker container
  docker_container:
    name: pytivo
    image: pinion/docker-pytivo
    pull: true
    ports:
      - "9032:9032"
      - "2190:2190/udp"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "{{ pytivo_config_directory }}:/config:rw"
      - "{{ pytivo_movies_directory }}:/movies:ro"
      - "{{ pytivo_tv_directory }}:/tv:ro"
      - "{{ pytivo_photos_directory }}:/photos:ro"
      - "{{ pytivo_music_directory }}:/music:ro"
      - "{{ pytivo_podcasts_directory }}:/podcasts:ro"
    network_mode: "host"
    env:
      TZ: "{{ ansible_nas_timezone }}"
      PUID: "{{ pytivo_user_id }}"
      PGID: "{{ pytivo_group_id }}"
    restart_policy: unless-stopped
    memory: 1g
    labels:
      traefik.backend: "pytivo"
      traefik.frontend.rule: "Host:pytivo.{{ ansible_nas_domain }}"
      traefik.enable: "{{ pytivo_available_externally }}"
      traefik.port: "9032"