---
- name: Early dependencies installed
  apt:
    name: gnupg2,python3-pip
    state: latest

- name: Mopidy apt gpg key installed
  shell: "wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -"

- name: Mopidy apt repo added
  shell: "wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/buster.list"

- name: Package cache updated
  shell: apt update

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

- name: Playlist folder exists
  file:
    path: /var/lib/mopidy/playlists
    owner: mopidy
    group: audio
    mode: 0755
    state: directory

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

- name: Mopidy dependencies up-to-date
  shell: "pip3 install mopidy-iris mopidy-muse mopidy-musicbox-webclient mopidy-mowecl mopidy-mobile mopidy-party"

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