From 8e04a9c9502b2082b3520e42bf7a3d7dea45b6e4 Mon Sep 17 00:00:00 2001 From: Ben Kristinsson Date: Mon, 1 May 2023 00:28:07 +0200 Subject: [PATCH] homeaudio --- roles/airconnect/defaults/main.yml | 2 + roles/airconnect/handlers/main.yml | 11 ++- roles/airconnect/tasks/airconnect.yml | 2 +- roles/airconnect/templates/airupnp.xml.j2 | 10 ++- .../files/mopidy-archive-keyring.gpg | Bin 0 -> 2232 bytes roles/homeaudio/tasks/homeaudio.yml | 21 +++++ roles/homeaudio/tasks/main.yml | 7 ++ roles/homeaudio/tasks/mopidy.yml | 84 ++++++++++++++++++ roles/homeaudio/templates/mopidy.conf.j2 | 27 ++++++ roles/owntone/handlers/main.yml | 4 +- roles/owntone/tasks/owntone.yml | 22 +---- roles/owntone/templates/01-owntone.conf.j2 | 15 ++-- roles/owntone/templates/owntone-cron.j2 | 2 +- roles/owntone/templates/owntone.conf.j2 | 32 +++---- 14 files changed, 188 insertions(+), 51 deletions(-) create mode 100644 roles/homeaudio/files/mopidy-archive-keyring.gpg create mode 100644 roles/homeaudio/tasks/homeaudio.yml create mode 100644 roles/homeaudio/tasks/main.yml create mode 100644 roles/homeaudio/tasks/mopidy.yml create mode 100644 roles/homeaudio/templates/mopidy.conf.j2 diff --git a/roles/airconnect/defaults/main.yml b/roles/airconnect/defaults/main.yml index d9a2267..710f734 100644 --- a/roles/airconnect/defaults/main.yml +++ b/roles/airconnect/defaults/main.yml @@ -8,6 +8,8 @@ airconnect_group: name: airconnect gid: 1337 + +airconnect_max_volume: "100" airconnect_upnp: [] airconnect_containers: # UPnP/Sonos diff --git a/roles/airconnect/handlers/main.yml b/roles/airconnect/handlers/main.yml index 9d28fe2..6a26e45 100644 --- a/roles/airconnect/handlers/main.yml +++ b/roles/airconnect/handlers/main.yml @@ -2,10 +2,13 @@ - name: restart airconnect containers docker_container: - name: airconnect-{{ item }} + name: airconnect-{{ item.prog }} state: "{{ item.state }}" - restart: item.state == 'started' + restart: "{% if item.state|default('started') == 'started' %}true{% else %}false{% endif %}" + loop_control: + label: "{{ item.prog }}" with_items: "{{ airconnect_containers }}" when: - - airconnect_containers is not defined or not airconnect_containers.changed - - item.state == 'started' + - airconnect_containers is not defined or not airconnect_containers_task.changed + - item.state|default("started") == "started" + - airconnect_restart_handler|default(true) diff --git a/roles/airconnect/tasks/airconnect.yml b/roles/airconnect/tasks/airconnect.yml index 7480ec7..5cf34aa 100644 --- a/roles/airconnect/tasks/airconnect.yml +++ b/roles/airconnect/tasks/airconnect.yml @@ -50,7 +50,7 @@ - airconnect - airconnect-container - docker-containers - register: airconnect_containers + register: airconnect_containers_task loop_control: label: airconnect-{{ item.prog }} with_items: "{{ airconnect_containers }}" diff --git a/roles/airconnect/templates/airupnp.xml.j2 b/roles/airconnect/templates/airupnp.xml.j2 index 5b2b84e..9b64590 100644 --- a/roles/airconnect/templates/airupnp.xml.j2 +++ b/roles/airconnect/templates/airupnp.xml.j2 @@ -8,14 +8,14 @@ http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=00;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=0d500000000000000000000000000000 1 - 100 + {{ airconnect_max_volume }} -1 1 mp3:320 1 1 - 0:1000 + 0:500 0 info @@ -28,9 +28,11 @@ 0:0 {% for item in airconnect_upnp -%} - uuid:{{ item.local_uid }} + uuid:{{ item.local_uuid }} {{ item.name }} - {{ item.mac }} + {% if 'mac' in item -%} + {{ item.mac | upper }} + {% endif -%} {% if item.enabled|default(true) %}1{% else %}0{% endif %} {% endfor %} diff --git a/roles/homeaudio/files/mopidy-archive-keyring.gpg b/roles/homeaudio/files/mopidy-archive-keyring.gpg new file mode 100644 index 0000000000000000000000000000000000000000..28796384d0604eb3aafba7285233f2ec8eabf24b GIT binary patch literal 2232 zcmV;p2uJss0u2OA*98^<5CFzn#l#t}mU4wmzoeeLqscUpUY_5s(5_G{=U*xx6 zSYA4;(M(aUgFgjMj-K#!j;6sm*6isi9JZuC(DP|U%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E8_^>-B#$okHl{P}im-%EUYC^0UkNBvDK9Xy zlbJVwegrsU;p9s{^9tEgCmA%1EY<)ej_)KljkBU^ncJNAIS*xoc)?P+#=x*cZ2E1D zVA&O;b5XgNXUJFMuphv@n>8*Yv0zfwd94sy3aAY9LJWdSqbx01*KI0f_=11Q-DV00{*GOxFb#0vikf3JDN+ z{g@6X9VtUVZx8=|C9}xRIh%+6q9KEp}GXJBS4;p!XDQD9zzc~8D!?w%xo^nfEPJhiZ zSJ7QhYC1V*V}uPoQyu0Qauo$^HmPb91P0Ezh4xO3wERlgDVPzir%hf0=^A;{DQB= z%nGmVX0~$JARzUUE4?jTq3jYk;Usm>WTpaUm*I!HD`>#cO7AD+8;to;_F(2$?S+-G zoS~%070AYv=~N%cf6@$2^TZ_5=XE5z_;zq{n#vUZQcjiaYtaepp^yALVVFwiP z?Vk|yqTLA(bG*#2ycP}Mb|lbW+b_kOoLp@((&!-;ugRaCbcTKG;QD;s3&)y*&GQOm zId)PC6u7%VtF6k`0|R}pmrqG>xqFxo9K|I3FCnn3(@(-coRO?tt!L6w$~v*7qvk&{ G_~mD3tT~bZ literal 0 HcmV?d00001 diff --git a/roles/homeaudio/tasks/homeaudio.yml b/roles/homeaudio/tasks/homeaudio.yml new file mode 100644 index 0000000..b85f807 --- /dev/null +++ b/roles/homeaudio/tasks/homeaudio.yml @@ -0,0 +1,21 @@ +--- + +- name: install audio and metadata related packages + apt: + name: + - avahi-utils + - id3v2 + - ffmpeg + state: present + tags: + - homeaudio-packages + +- name: install yt-dlp + pip: + name: yt-dlp + state: latest + tags: + - packages + - pip-packages + - yt-dlp + - homeaudio-packages diff --git a/roles/homeaudio/tasks/main.yml b/roles/homeaudio/tasks/main.yml new file mode 100644 index 0000000..b5dd627 --- /dev/null +++ b/roles/homeaudio/tasks/main.yml @@ -0,0 +1,7 @@ +--- + +- import_tasks: homeaudio.yml + tags: homeaudio + +- import_tasks: mopidy.yml + tags: mopidy diff --git a/roles/homeaudio/tasks/mopidy.yml b/roles/homeaudio/tasks/mopidy.yml new file mode 100644 index 0000000..7a67aa8 --- /dev/null +++ b/roles/homeaudio/tasks/mopidy.yml @@ -0,0 +1,84 @@ +--- + +- name: copy key for mopidy repo + copy: + src: mopidy-archive-keyring.gpg + dest: /usr/local/share/keyrings/mopidy-archive-keyring.gpg + owner: root + group: root + mode: "0644" + tags: + - mopidy + +- name: add mopidy repo + apt_repository: + repo: "{{ item }}" + state: present + update_cache: false + filename: /etc/apt/sources.list.d/mopidy + with_items: + - "deb [signed-by=/usr/local/share/keyrings/mopidy-archive-keyring.gpg] https://apt.mopidy.com/ buster main contrib non-free" + - "deb-src [signed-by=/usr/local/share/keyrings/mopidy-archive-keyring.gpg] https://apt.mopidy.com/ buster main contrib non-free" + register: mopidy_repo + tags: + - mopidy + - packages + +- name: apt-get update if repo changed + apt: + update_cache: true + when: mopidy_repo.changed + tags: + - mopidy + - packages + +- name: install mopidy + apt: + name: + - mopidy + - mopidy-podcast + - mopidy-soundcloud + - mopidy-internetarchive + - mopidy-local + - mopidy-mpd + - mopidy-podcast-itunes + - mopidy-podcast + - mopidy-soundcloud + - mopidy-internetarchive + - mopidy-local + - mopidy-mpd + - mopidy-podcast-itunes + - mopidy-spotify + - mopidy-mpris + - upnp-inspector + # - playerctl + #- upmpdcli + state: present + tags: + - mopidy + - packages + +- name: install mopidy pip packages + pip: + name: + - Mopidy-Jellyfin + - Mopidy-RadioNet + - Mopidy-YouTube + - Mopidy-Iris + - Mopidy-Autoplay + state: present + tags: + - mopidy + - packages + - pip-packages + +- name: template mopdiy config + template: + src: mopidy.conf.j2 + dest: /etc/mopidy/mopdy.conf + owner: mopidy + group: root + mode: "0640" + tags: + - mopidy + - mopidy.conf diff --git a/roles/homeaudio/templates/mopidy.conf.j2 b/roles/homeaudio/templates/mopidy.conf.j2 new file mode 100644 index 0000000..4224a52 --- /dev/null +++ b/roles/homeaudio/templates/mopidy.conf.j2 @@ -0,0 +1,27 @@ +# For information about configuration values that can be set in this file see: +# +# https://docs.mopidy.com/en/latest/config/ +# +# Run `sudo mopidyctl config` to see the current effective config, based on +# both defaults and this configuration file. +[http] +enabled = true +hostname = 0.0.0.0 +port = 6680 +zeroconf = Mopidy HTTP server on $hostname +allowed_origins = +csrf_protection = true +default_app = mopidy + +[mpd] +enabled = false +hostname = 127.0.0.1 +port = 6600 +password = +max_connections = 20 +connection_timeout = 60 +zeroconf = Mopidy MPD server on $hostname +command_blacklist = + listall + listallinfo +default_playlist_scheme = m3u diff --git a/roles/owntone/handlers/main.yml b/roles/owntone/handlers/main.yml index 34e6178..708cd91 100644 --- a/roles/owntone/handlers/main.yml +++ b/roles/owntone/handlers/main.yml @@ -7,6 +7,8 @@ - name: restart owntone container docker_container: - name: hass + name: owntone state: started restart: true + when: + - owntone_restart_handler|default(true) diff --git a/roles/owntone/tasks/owntone.yml b/roles/owntone/tasks/owntone.yml index 3bc8cb5..d46ca4c 100644 --- a/roles/owntone/tasks/owntone.yml +++ b/roles/owntone/tasks/owntone.yml @@ -10,7 +10,7 @@ tags: - owntone-dirs loop_control: - label: "{{ item.name }}" + label: "{{ owntone_path }}/{{ item.name }}" with_items: - name: '' - name: config @@ -36,6 +36,8 @@ - shairport-metadata.fifo tags: - input.fifo + # disabled + when: false - name: install certs copy: @@ -87,24 +89,6 @@ - cron - owntone-cron -- name: install utils for tagging - apt: - name: - - - id3v2 - - ffmpeg - state: present - tags: - - packages - -- name: install yt-dlp - pip: - name: yt-dlp - state: latest - tags: - - packages - - pip-packages - - yt-dlp - name: fuse allow other lineinfile: diff --git a/roles/owntone/templates/01-owntone.conf.j2 b/roles/owntone/templates/01-owntone.conf.j2 index 559df50..69dff5e 100644 --- a/roles/owntone/templates/01-owntone.conf.j2 +++ b/roles/owntone/templates/01-owntone.conf.j2 @@ -1,5 +1,7 @@ server { + listen 444 ssl; listen 443 ssl http2; + # listen 443 ssl http2; # listen {{ owntone_port_tcp }}; {% if inventory_hostname in wg_clients -%} @@ -29,12 +31,15 @@ server { sub_filter_types '*'; sub_filter_once off; - proxy_pass http://127.0.0.1:{{ owntone_port_tcp }}/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:{{ owntone_port_tcp }}$request_uri; proxy_http_version 1.1; + + proxy_set_header Host "{{ owntone_url }}"; + #proxy_set_header Host "owntone.local:3689"; + + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } diff --git a/roles/owntone/templates/owntone-cron.j2 b/roles/owntone/templates/owntone-cron.j2 index b79dde9..c6c3415 100644 --- a/roles/owntone/templates/owntone-cron.j2 +++ b/roles/owntone/templates/owntone-cron.j2 @@ -2,6 +2,6 @@ # m h dom mon dow -*/60 * * * * {{ owntone_user.username }} touch {{ owntone_path }}/audio/local_music/trigger.init-rescan +*/60 * * * * {{ owntone_user.username }} touch {{ owntone_path }}/audio/trigger.init-rescan # diff --git a/roles/owntone/templates/owntone.conf.j2 b/roles/owntone/templates/owntone.conf.j2 index 8e0214b..390157a 100644 --- a/roles/owntone/templates/owntone.conf.j2 +++ b/roles/owntone/templates/owntone.conf.j2 @@ -1,12 +1,3 @@ -# A quick guide to configuring OwnTone: -# -# For regular use, the most important setting to configure is "directories", -# which should be the location of your media. Whatever user you have set as -# "uid" must have read access to this location. If the location is a network -# mount, please see the README. -# -# In all likelihood, that's all you need to do! - general { # Username # Make sure the user has read access to the library directories you set @@ -197,7 +188,7 @@ library { # Watch named pipes in the library for data and autostart playback when # there is data to be read. To exclude specific pipes from watching, # consider using the above _ignore options. - pipe_autostart = true + pipe_autostart = false # Enable automatic rating updates # If enabled, rating is automatically updated after a song has either been @@ -208,7 +199,7 @@ library { # skipcount and a rolling rating based on the current rating and the action # (played or skipped). Both results are combined with a mix-factor of 0.75: # new rating = 0.75 * stable rating + 0.25 * rolling rating) - #rating_updates = false + rating_updates = false # Allows creating, deleting and modifying m3u playlists in the library directories. # Only supported by the player web interface and some mpd clients @@ -255,7 +246,7 @@ audio { # e.g. Airplay. This feature relies on accurate ALSA measurements of # delay, and some devices dont provide that. If that is the case you # are better off disabling the feature. - #sync_disable = false + sync_disable = false # Here you can adjust when local audio is started relative to other # speakers, e.g. Airplay. Negative values correspond to moving local @@ -290,10 +281,11 @@ audio { # Pipe output # Allows OwnTone to output audio data to a named pipe -fifo { - nickname = "fifo" - path = "/audio/output.fifo" -} +# fifo { +# nickname = "fifo" +# # placed outside of library +# path = "/tmp/output.fifo" +# } # AirPlay settings common to all devices #airplay_shared { @@ -369,6 +361,14 @@ airplay "{{ item.name }}" { # Name used in the speaker list, overrides name from the device #nickname = "My speaker name" # } +{% for item in owntone_chromecast -%} +chromecast "{{item.name }}" { + exclude = {{ item.exclude|default(false) | lower }} + {%- if 'nickname' in item -%} + nickname = "{{ item.nickname }}" + {% endif +%} +} +{% endfor %} # Spotify settings (only have effect if Spotify enabled - see README/INSTALL) spotify { -- 2.40.1