diff --git a/hosts b/hosts index 31415d3..b3def02 100644 --- a/hosts +++ b/hosts @@ -3,3 +3,6 @@ bank-pi.bitlair.nl [mqtt_internal] mqtt.bitlair.nl + +[music] +music.bitlair.nl diff --git a/roles/music/defaults/main.yaml b/roles/music/defaults/main.yaml new file mode 100644 index 0000000..3b9e2b6 --- /dev/null +++ b/roles/music/defaults/main.yaml @@ -0,0 +1 @@ +music_audio_user: audio diff --git a/roles/music/handlers/main.yaml b/roles/music/handlers/main.yaml new file mode 100644 index 0000000..957ee6f --- /dev/null +++ b/roles/music/handlers/main.yaml @@ -0,0 +1,28 @@ +--- +- name: reload nginx + systemd: + name: nginx + state: reloaded + +- name: rebuild trollibox + command: ./build.sh + args: + chdir: /opt/trollibox + environment: { RELEASE: 1 } + +- name: restart trollibox + systemd: + name: trollibox + state: restarted + daemon_reload: true + +- name: rebuild librespot + command: cargo build --release --features jackaudio-backend + args: + chdir: /opt/librespot + +- name: restart librespot + systemd: + name: librespot + state: restarted + daemon_reload: true diff --git a/roles/music/tasks/librespot.yaml b/roles/music/tasks/librespot.yaml new file mode 100644 index 0000000..22ceac3 --- /dev/null +++ b/roles/music/tasks/librespot.yaml @@ -0,0 +1,31 @@ +--- +- name: Install dependencies + apt: + name: libjack-jackd2-dev + state: present + +- name: Clone librespot source + git: + repo: https://github.com/librespot-org/librespot.git + version: dev + dest: /opt/librespot + accept_hostkey: yes + notify: + - rebuild librespot + - restart librespot + +- name: Install service file + template: + src: librespot.service + dest: /etc/systemd/system/librespot.service + owner: root + group: root + mode: 0644 + notify: restart librespot + +- name: Enable Librespot + systemd: + name: librespot + state: started + enabled: true + daemon_reload: true diff --git a/roles/music/tasks/main.yaml b/roles/music/tasks/main.yaml new file mode 100644 index 0000000..6171897 --- /dev/null +++ b/roles/music/tasks/main.yaml @@ -0,0 +1,9 @@ +--- +- tags: music_mpd + include_tasks: mpd.yaml + +- tags: music_trollibox + include_tasks: trollibox.yaml + +- tags: music_librespot + include_tasks: librespot.yaml diff --git a/roles/music/tasks/mpd.yaml b/roles/music/tasks/mpd.yaml new file mode 100644 index 0000000..78c9581 --- /dev/null +++ b/roles/music/tasks/mpd.yaml @@ -0,0 +1,7 @@ +--- +- name: Install MPD + apt: + name: + - jackd + - mpd + state: present diff --git a/roles/music/tasks/trollibox.yaml b/roles/music/tasks/trollibox.yaml new file mode 100644 index 0000000..f707b26 --- /dev/null +++ b/roles/music/tasks/trollibox.yaml @@ -0,0 +1,29 @@ +--- +- name: Clone trollibox source + git: + repo: https://github.com/polyfloyd/trollibox.git + version: master + dest: /opt/trollibox + accept_hostkey: yes + notify: + - rebuild trollibox + - restart trollibox + +- name: Initial build + meta: flush_handlers + +- name: Install service file + template: + src: trollibox.service + dest: /etc/systemd/system/trollibox.service + owner: root + group: root + mode: 0644 + notify: restart trollibox + +- name: Enable Trollibox + systemd: + name: trollibox + state: started + enabled: true + daemon_reload: true diff --git a/roles/music/templates/librespot.service b/roles/music/templates/librespot.service new file mode 100644 index 0000000..c66da9c --- /dev/null +++ b/roles/music/templates/librespot.service @@ -0,0 +1,20 @@ +# +# Managed by Ansible +# + +[Unit] +Description=Spotify through Librespot +After=network.target +Requires=jackd.service + +[Service] +Type=simple +Restart=always +RestartSec=2s +ExecStart=/opt/librespot/target/release/librespot --name Trollibox --backend jackaudio +User={{ music_audio_user }} +Group={{ music_audio_user }} +AmbientCapabilities=CAP_IPC_LOCK,CAP_SYS_NICE + +[Install] +WantedBy=multi-user.target diff --git a/roles/music/templates/trollibox.service b/roles/music/templates/trollibox.service new file mode 100644 index 0000000..6dd9041 --- /dev/null +++ b/roles/music/templates/trollibox.service @@ -0,0 +1,19 @@ +# +# Managed by Ansible +# + +[Unit] +Description=Trollibox +After=mpd.service network.target +Requires=mpd.service + +[Service] +Type=simple +Restart=always +RestartSec=2s +ExecStart=/opt/trollibox/bin/trollibox -conf /etc/trollibox.yaml +User={{ music_audio_user }} +Group={{ music_audio_user }} + +[Install] +WantedBy=multi-user.target