diff --git a/roles/arch/defaults/main/main.yml b/roles/arch/defaults/main/main.yml index 7d53547..c96d116 100644 --- a/roles/arch/defaults/main/main.yml +++ b/roles/arch/defaults/main/main.yml @@ -1,4 +1,5 @@ xdg_config_dir: "{{ ansible_env.HOME }}/.config" +xdg_script_dir: "{{ ansible_env.HOME }}/.local/bin" packages: - firefox diff --git a/roles/arch/defaults/main/mpd.yml b/roles/arch/defaults/main/mpd.yml new file mode 100644 index 0000000..639171a --- /dev/null +++ b/roles/arch/defaults/main/mpd.yml @@ -0,0 +1,11 @@ +mpd_listen_address: "127.0.0.1" +mpd_listen_port: "6600" + +mpd_database_address: "10.8.0.1" +mpd_database_port: "21000" + +mpd_configuration_dir: "{{ ansible_env.HOME }}/.config/mpd" +mpd_music_dir: "{{ ansible_env.HOME }}/music" +mpd_playlist_dir: "{{ mpd_configuration_dir }}/playlists" +mpd_state_path: "{{ mpd_configuration_dir }}/state" +mpd_sticker_path: "{{ mpd_configuration_dir }}/sticker.sql" diff --git a/roles/arch/tasks/main.yml b/roles/arch/tasks/main.yml index b605b7f..163ae4b 100644 --- a/roles/arch/tasks/main.yml +++ b/roles/arch/tasks/main.yml @@ -50,8 +50,7 @@ - include_tasks: gpg.yml # TODO - include_tasks: git.yml # TODO - include_tasks: mpv.yml -- include_tasks: mpd.yml # TODO -- include_tasks: nfs.yml # TODO +- include_tasks: mpd.yml - include_tasks: postgres.yml # TODO - include_tasks: syncthing.yml # TODO depending on platform - include_tasks: openvpn.yml # TODO (laptop) diff --git a/roles/arch/tasks/mpd.yml b/roles/arch/tasks/mpd.yml index e69de29..22b3f09 100644 --- a/roles/arch/tasks/mpd.yml +++ b/roles/arch/tasks/mpd.yml @@ -0,0 +1,88 @@ +- name: set up sudoers configuration + become: yes + template: + src: "sudoers.j2" + dest: "/etc/sudoers.d/10-sonny" + owner: root + group: root + mode: "0644" + +- name: copy systemd configuration files + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + loop: + - { + src: "mpd/service.j2", + dest: "{{ xdg_config_dir }}/systemd/user/mpd.service", + } + - { + src: "mpd/socket.j2", + dest: "{{ xdg_config_dir }}/systemd/user/mpd.socket", + } + +- name: create mpd files + file: + path: "{{ item.path }}" + state: "{{ item.state }}" + loop: + - { + path: "{{ mpd_configuration_dir }}", + state: "directory", + } + - { + path: "{{ mpd_configuration_dir }}/playlists", + state: "directory", + } + - { + path: "{{ mpd_configuration_dir }}/log", + state: "touch", + } + - { + path: "{{ mpd_configuration_dir }}/database", + state: "touch", + } + - { + path: "{{ mpd_configuration_dir }}/sticker.sql", + state: "touch", + } + - { + path: "{{ mpd_configuration_dir }}/state", + state: "touch", + } + +- name: copy configuration file + template: + src: "mpd/mpd.j2" + dest: "{{ mpd_configuration_dir }}/mpd.conf" + +- name: copy nfs connection scripts + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + mode: "0755" + loop: + - { + src: "mpd/music_mount.j2", + dest: "{{ xdg_script_dir }}/music_mount", + } + - { + src: "mpd/music_umount.j2", + dest: "{{ xdg_script_dir }}/music_umount", + } + +- name: restart mpd service + systemd: + name: mpd.service + state: restarted + enabled: no + scope: user + when: platform == "desktop" + +- name: enable mpd socket + systemd: + name: mpd.socket + state: started + enabled: yes + scope: user + when: platform == "desktop" diff --git a/roles/arch/tasks/nfs.yml b/roles/arch/tasks/nfs.yml deleted file mode 100644 index e69de29..0000000 diff --git a/roles/arch/templates/mpd/mpd.j2 b/roles/arch/templates/mpd/mpd.j2 new file mode 100644 index 0000000..24ec414 --- /dev/null +++ b/roles/arch/templates/mpd/mpd.j2 @@ -0,0 +1,44 @@ +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +music_directory "{{ mpd_music_dir }}" +playlist_directory "{{ mpd_playlist_dir }}" +state_file "{{ mpd_state_path }}" +sticker_file "{{ mpd_sticker_path }}" +log_level "secure" + +bind_to_address "{{ mpd_listen_address }}" +port "{{ mpd_listen_port }}" + +auto_update "yes" +filesystem_charset "UTF-8" + +samplerate_converter "1" + +database { + plugin "proxy" + host "{{ mpd_database_address }}" + port "{{ mpd_database_port }}" +} + +audio_output { + type "pulse" + name "mpd" + replay_gain_handler "software" + mixer_type "hardware" + format "96000:24:1" +} + +input { + enabled "no" + plugin "tidal" +} + +input { + enabled "no" + plugin "qobuz" +} + +decoder { + plugin "wildmidi" + enabled "no" +} diff --git a/roles/arch/templates/mpd/music_mount.j2 b/roles/arch/templates/mpd/music_mount.j2 new file mode 100644 index 0000000..615712b --- /dev/null +++ b/roles/arch/templates/mpd/music_mount.j2 @@ -0,0 +1,5 @@ +#!/bin/bash +# +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +sudo mount -t nfs -o vers=4,soft,async,proto=tcp,port=2049 10.8.0.1:/srv/nfs4/music {{ mpd_music_dir }} diff --git a/roles/arch/templates/mpd/music_umount.j2 b/roles/arch/templates/mpd/music_umount.j2 new file mode 100644 index 0000000..9bc55a2 --- /dev/null +++ b/roles/arch/templates/mpd/music_umount.j2 @@ -0,0 +1,6 @@ +#!/bin/bash +# +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +pkill cantata +sudo umount {{ mpd_music_dir }} diff --git a/roles/arch/templates/mpd/service.j2 b/roles/arch/templates/mpd/service.j2 new file mode 100644 index 0000000..dd79222 --- /dev/null +++ b/roles/arch/templates/mpd/service.j2 @@ -0,0 +1,14 @@ +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +[Unit] +Description=Music Player Daemon +Documentation=man:mpd(1) man:mpd.conf(5) + +[Service] +Type=notify +ExecStartPre={{ xdg_script_dir }}/music_mount +ExecStart=/usr/bin/mpd --no-daemon {{ mpd_configuration_dir }}/mpd.conf +ExecStopPost={{ xdg_script_dir }}/music_umount +Restart=on-failure +RestartSec=15s +TimeoutStopSec=3 diff --git a/roles/arch/templates/mpd/socket.j2 b/roles/arch/templates/mpd/socket.j2 new file mode 100644 index 0000000..7188f2c --- /dev/null +++ b/roles/arch/templates/mpd/socket.j2 @@ -0,0 +1,11 @@ +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +[Socket] +ListenStream=/run/user/1000/mpd.socket +ListenStream={{ mpd_listen_port }} +Backlog=5 +KeepAlive=true +PassCredentials=true + +[Install] +WantedBy=sockets.target diff --git a/roles/arch/templates/sudoers.j2 b/roles/arch/templates/sudoers.j2 new file mode 100644 index 0000000..5d41d4c --- /dev/null +++ b/roles/arch/templates/sudoers.j2 @@ -0,0 +1,4 @@ +# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} + +sonny ALL=(ALL) NOPASSWD: /usr/bin/mount +sonny ALL=(ALL) NOPASSWD: /usr/bin/umount