From 2a54ec3ec639a8a83871ffcac05f16a1715faf63 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Fri, 15 Apr 2022 11:58:11 +0200 Subject: [PATCH] music: Add Librespot --- roles/music/handlers/main.yaml | 11 +++++++++ roles/music/tasks/librespot.yaml | 31 +++++++++++++++++++++++++ roles/music/tasks/main.yaml | 3 +++ roles/music/templates/librespot.service | 20 ++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 roles/music/tasks/librespot.yaml create mode 100644 roles/music/templates/librespot.service diff --git a/roles/music/handlers/main.yaml b/roles/music/handlers/main.yaml index 43f7a73..957ee6f 100644 --- a/roles/music/handlers/main.yaml +++ b/roles/music/handlers/main.yaml @@ -15,3 +15,14 @@ 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 index 5bb042b..6171897 100644 --- a/roles/music/tasks/main.yaml +++ b/roles/music/tasks/main.yaml @@ -4,3 +4,6 @@ - tags: music_trollibox include_tasks: trollibox.yaml + +- tags: music_librespot + include_tasks: librespot.yaml 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