From f24e8b6436dc850414eb099786f897509478903a Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Sat, 2 Oct 2021 16:31:21 +0200 Subject: [PATCH 1/4] Add a role to install Trollibox --- hosts | 3 +++ roles/music/handlers/main.yaml | 17 +++++++++++++++++ roles/music/tasks/main.yaml | 3 +++ roles/music/tasks/trollibox.yaml | 13 +++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 roles/music/handlers/main.yaml create mode 100644 roles/music/tasks/main.yaml create mode 100644 roles/music/tasks/trollibox.yaml 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/handlers/main.yaml b/roles/music/handlers/main.yaml new file mode 100644 index 0000000..43f7a73 --- /dev/null +++ b/roles/music/handlers/main.yaml @@ -0,0 +1,17 @@ +--- +- 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 diff --git a/roles/music/tasks/main.yaml b/roles/music/tasks/main.yaml new file mode 100644 index 0000000..73a6ac8 --- /dev/null +++ b/roles/music/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- tags: music_trollibox + include: trollibox.yaml diff --git a/roles/music/tasks/trollibox.yaml b/roles/music/tasks/trollibox.yaml new file mode 100644 index 0000000..1e094eb --- /dev/null +++ b/roles/music/tasks/trollibox.yaml @@ -0,0 +1,13 @@ +--- +- 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 From f8dd32b23461bbeeea1bfa5978ec6933464b45ef Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Thu, 14 Apr 2022 19:33:21 +0200 Subject: [PATCH 2/4] s/include/include_tasks/ --- roles/music/tasks/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/music/tasks/main.yaml b/roles/music/tasks/main.yaml index 73a6ac8..f239de7 100644 --- a/roles/music/tasks/main.yaml +++ b/roles/music/tasks/main.yaml @@ -1,3 +1,3 @@ --- - tags: music_trollibox - include: trollibox.yaml + include_tasks: trollibox.yaml From 7356db2b8a5b6e0fac433183bf3f30d29f3d368f Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Fri, 15 Apr 2022 11:57:44 +0200 Subject: [PATCH 3/4] music: Extend Trollibox installation --- roles/music/defaults/main.yaml | 1 + roles/music/tasks/main.yaml | 3 +++ roles/music/tasks/mpd.yaml | 7 +++++++ roles/music/tasks/trollibox.yaml | 16 ++++++++++++++++ roles/music/templates/trollibox.service | 19 +++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 roles/music/defaults/main.yaml create mode 100644 roles/music/tasks/mpd.yaml create mode 100644 roles/music/templates/trollibox.service 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/tasks/main.yaml b/roles/music/tasks/main.yaml index f239de7..5bb042b 100644 --- a/roles/music/tasks/main.yaml +++ b/roles/music/tasks/main.yaml @@ -1,3 +1,6 @@ --- +- tags: music_mpd + include_tasks: mpd.yaml + - tags: music_trollibox include_tasks: trollibox.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 index 1e094eb..f707b26 100644 --- a/roles/music/tasks/trollibox.yaml +++ b/roles/music/tasks/trollibox.yaml @@ -11,3 +11,19 @@ - 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/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 From 2a54ec3ec639a8a83871ffcac05f16a1715faf63 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Fri, 15 Apr 2022 11:58:11 +0200 Subject: [PATCH 4/4] 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