---
- name: Dependencies installed
  community.general.pkgng:
    name: py38-pip py38-sqlite3 py38-gstreamer1 avahi-daemon
    state: latest

- name: Dependencies installed
  apt:
    name: mopidy,mopidy-spotify,mopidy-soundcloud,mopidy-mpd,mopidy-podcast,mopidy-tunein,mopidy-local
    state: latest

- name: mDNS disabled
  shell: sysrc mdns_enable="NO"

- name: mDNS stopped
  service:
    name: mdns
    state: stopped

- name: Avahi enabled
  shell: sysrc avahi_daemon_enable="YES"

- name: Avahi started
  service:
    name: avahi-daemon
    state: started

- name: Media folder exists
  file:
    path: /var/lib/mopidy/media
    owner: mopidy
    mode: 0775
    state: directory

- name: Music folder exists
  file:
    path: /var/lib/mopidy/media/music
    owner: mopidy
    mode: 0775
    state: directory

- name: Music folder exists
  file:
    path: /var/lib/mopidy/media/podcasts
    owner: mopidy
    mode: 0775
    state: directory

- name: Mopidy dependencies up-to-date
  shell: "pip3 install mopidy-iris mopidy-muse mopidy-musicbox-webclient mopidy-mowecl mopidy-mobile mopidy-party mopidy-tidal mopidy-mpd mopidy-tunein mopidy-jellyfin mopidy-bookmarks mopidy-local"

- name: Mopidy settings installed
  template:
    src: mopidy.conf.j2
    dest: /usr/local/etc/mopidy/mopidy.conf
    owner: root
    mode: 0664
  notify: Immortal restarted

- name: Mopidy immortal file installed
  copy:
    src: immortal.yml
    dest: /usr/local/etc/immortal/mopidy.yml
    owner: root
    mode: 0600
  notify: Immortal restarted
