feat!: Refactor configuration

Docker-config is more flexible.
Configuration is more hierarchical (except paths).
This commit is contained in:
Laur Ivan 2023-01-22 19:36:10 +01:00
parent ab2ff91939
commit 9d870bb96d
13 changed files with 151 additions and 110 deletions

1
.env.yml Normal file
View File

@ -0,0 +1 @@
bonob.enabled: "true"

17
.gitignore vendored
View File

@ -1,7 +1,14 @@
*.retry tests/playbook.retry
*/__pycache__ tests/.cache
*.pyc __pycache__
.pytest_cache
.molecule
.cache .cache
.venv .venv
.env.yml
docker-compose.yml *.iml
.idea
.project
*.pyc
**/.vscode

View File

@ -15,64 +15,64 @@ All variables are listed below (see also `defaults/main.yml`).
You can (and should) specify the version of the navidrome image: You can (and should) specify the version of the navidrome image:
```yaml ```yaml
navidrome_image_version: 'latest' navidrome.image_version: 'latest'
``` ```
Navidrome needs a place to store its configuration and another to pick up music from: Navidrome needs a place to store its configuration and another to pick up music from:
```yaml ```yaml
navidrome_config_volume: '/mnt/config-local/navidrome' navidrome.config_volume: '/mnt/config-local/navidrome'
navidrome_music_volume: '/mnt/music' navidrome.music_volume: '/mnt/music'
``` ```
If you have multiple folders with music, you should create a parent and build symbolic links to them. If you have multiple folders with music, you should create a parent and build symbolic links to them.
The web interface is available at the following port: The web interface is available at the following port:
```yaml ```yaml
navidrome_host_port: 48533 navidrome.host_port: 48533
``` ```
### Bonob ### Bonob
If you have e.g. a Sonos system in the house, you may install also Bonob by setting `bonob_enabled` to `true`. the default is: If you have e.g. a Sonos system in the house, you may install also Bonob by setting `bonob.enabled` to `true`. the default is:
```yml ```yml
bonob_enabled: false bonob.enabled: false
``` ```
You can also specify the bonob image version and the port at which is available: You can also specify the bonob image version and the port at which is available:
```yml ```yml
bonob_image_version: 'latest' bonob.image_version: 'latest'
bonob_host_port: 48534 bonob.host_port: 48534
``` ```
You can change the colors of the bonob icon displayed: You can change the colors of the bonob icon displayed:
```yml ```yml
bonob_icon_color: "beige" bonob.icon_color: "beige"
bonob_icon_background: "red" bonob.icon_background: "red"
``` ```
#### Sonos #### Sonos
The sonos-related variables are: The sonos-related variables are:
```yml ```yml
bonob_sonos_auto_register: 'true' bonob.sonos.auto_register: 'true'
bonob_sonos_device_discovery: 'true' bonob.sonos.device_discovery: 'true'
bonob_sonos_seed_host: bonob.sonos.seed_host:
bonob_sonos_service_id: "246" bonob.sonos.service_id: "246"
``` ```
If you try sonos autodiscovery and it doesn't work, please: If you try sonos autodiscovery and it doesn't work, please:
1. Find the IP of one of the Sonos devices 1. Find the IP of one of the Sonos devices
2. Set `bonob_sonos_seed_host` to that IP 2. Set `bonob.sonos.seed_host` to that IP
3. Replay the role 3. Replay the role
You can also add custom clients for streaming: You can also add custom clients for streaming:
```yaml ```yaml
bonob_subsonic_custom_clients: 'audio/flac' bonob.subsonic.custom_clients: 'audio/flac'
``` ```
For more details, please see the [Bonob documentation](https://github.com/simojenki/bonob). For more details, please see the [Bonob documentation](https://github.com/simojenki/bonob).
@ -97,7 +97,7 @@ A list of other roles hosted on Galaxy should go here, plus any details in regar
- name: Example playbook - name: Example playbook
hosts: services hosts: services
vars: vars:
bonob_enabled: "true" bonob.enabled: "true"
roles: roles:
- 'laurivan.navidrome' - 'laurivan.navidrome'

View File

@ -1,27 +1,37 @@
--- ---
# defaults file for navidrome # defaults file for navidrome
navidrome_image_version: 'latest' navidrome_root_path: /var/local/navidrome
navidrome_config_volume: "{{ navidrome_root_path }}/config"
navidrome_config_volume: '/mnt/config-local/navidrome' navidrome_docker_path: "{{ navidrome_root_path }}/docker"
navidrome_music_volume: '/mnt/music' navidrome_music_volume: '/mnt/music'
navidrome_host_port: 48533 navidrome_skeleton_paths:
- "{{ navidrome_docker_path }}"
- "{{ navidrome_config_volume }}"
timezone: 'Europe/Brussels' timezone: 'Europe/Brussels'
# Bonob navidrome:
bonob_enabled: false image_version: 'latest'
bonob_image_version: 'latest' host_port: 48533
bonob_host_port: 48534
bonob_icon_color: "beige"
bonob_icon_background: "red"
## Bonob sonos settings
bonob_sonos_auto_register: 'true' # Bonob
bonob_sonos_device_discovery: 'true' bonob:
bonob_sonos_seed_host: enabled: false
bonob_sonos_service_id: "246" image_version: 'latest'
host_port: 48534
icon_color: "beige"
icon_background: "red"
## Bonob sonos settings
sonos:
auto_register: 'true'
device_discovery: 'true'
seed_host:
service_id: "246"
## Subsonic ## Subsonic
bonob_subsonic_custom_clients: 'audio/flac' subsonic:
custom_clients: 'audio/flac'

46
tasks/config.yml Normal file
View File

@ -0,0 +1,46 @@
---
- name: "NAVIDROME | Set up directories"
ansible.builtin.file:
state: directory
path: "{{ item }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
mode: "0750"
with_items:
- "{{ navidrome_skeleton_paths }}"
tags:
- navidrome.configure
become: true
- name: "NAVIDROME | Write configuration files"
ansible.builtin.template:
src: "navidrome/{{ item }}.j2"
dest: "{{ navidrome_docker_path | expanduser | realpath }}/{{ item }}"
mode: '0640'
loop:
- "docker-compose.yml"
- "env.bonob.conf"
- "env.navidrome.conf"
tags:
- navidrome.configure
- name: "NAVIDROME | Check if the music volume exists"
ansible.builtin.stat:
path: "{{ navidrome_music_volume }}"
register: music
tags:
- navidrome.configure
- name: "NAVIDROME | Set up music volume"
ansible.builtin.file:
state: directory
path: "{{ navidrome_music_volume }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
mode: "0750"
tags:
- navidrome.configure
become: true
when: not music.stat.exists

9
tasks/install.yml Normal file
View File

@ -0,0 +1,9 @@
---
# Deploy navidrome
- name: "NAVIFROME | Ensure navirdome is running"
community.docker.docker_compose:
project_src: "{{ navidrome_docker_path | expanduser | realpath }}"
build: false
become: false

View File

@ -1,54 +1,11 @@
--- ---
# tasks file for navidrome
- name: Set up directories - name: "NAVIDROME | Configure"
ansible.builtin.file: import_tasks: config.yml
state: directory
path: "{{ item }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
mode: "0750"
with_items:
- "{{ navidrome_config_volume }}"
- "~/navidrome"
tags: tags:
- configuration - navidrome.configure
become: true
- name: Check if the music volume exists - name: "NAVIDROME | Install"
ansible.builtin.stat: import_tasks: install.yml
path: "{{ navidrome_music_volume }}"
register: music
tags: tags:
- configuration - navidrome.install
- name: Set up music volume
ansible.builtin.file:
state: directory
path: "{{ navidrome_music_volume }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
mode: "0750"
tags:
- configuration
become: true
when: not music.stat.exists
- name: Write configuration files
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "~/navidrome/{{ item }}"
mode: '0640'
loop:
- "docker-compose.yml"
- "env.navidrome.conf"
- "env.bonob.conf"
tags:
- configuration
- name: Ensure navirdome is running.
community.docker.docker_compose:
project_src: ~/navidrome/
build: false
become: false

View File

@ -1,15 +0,0 @@
{% if bonob_enabled %}
BNB_SONOS_AUTO_REGISTER={{ bonob_sonos_auto_register }}
BNB_SONOS_DEVICE_DISCOVERY={{ bonob_sonos_device_discovery }}
BNB_PORT=3000
{% if bonob_sonos_seed_host %}
BNB_SONOS_SEED_HOST={{ bonob_sonos_seed_host }}
{% endif %}
BNB_SUBSONIC_URL=http://navidrome:4533
BNB_SONOS_SERVICE_ID={{ bonob_sonos_service_id }}
BNB_URL=http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ bonob_host_port }}
BNB_SUBSONIC_CUSTOM_CLIENTS="audio/flac"
BNB_ICON_FOREGROUND_COLOR={{ bonob_icon_color }}
BNB_ICON_BACKGROUND_COLOR={{ bonob_icon_background }}
TZ={{ timezone }}
{% endif %}

View File

@ -1 +0,0 @@
TZ={{timezone}}

View File

@ -1,27 +1,28 @@
version: "3.3" version: "3.3"
services: services:
navidrome: navidrome:
image: "deluan/navidrome:{{ navidrome_image_version }}" image: "deluan/navidrome:{{ navidrome.image_version }}"
restart: always restart: always
env_file: env_file:
- ~/navidrome/env.navidrome.conf - "{{ navidrome_docker_path | expanduser | realpath }}/env.navidrome.conf"
volumes: volumes:
- {{ navidrome_config_volume }}:/data - {{ navidrome_config_volume }}:/data
- {{ navidrome_music_volume }}:/music:ro - {{ navidrome_music_volume }}:/music:ro
ports: ports:
- {{ navidrome_host_port }}:4533 - {{ navidrome.host_port }}:4533
networks: networks:
- navidrome - navidrome
{% if bonob_enabled %}
{% if bonob.enabled %}
bonob: bonob:
image: simojenki/bonob:{{ bonob_image_version }} image: simojenki/bonob:{{ bonob.image_version }}
restart: always restart: always
depends_on: depends_on:
- navidrome - navidrome
env_file: env_file:
- ~/navidrome/env.bonob.conf - "{{ navidrome_docker_path | expanduser | realpath }}/env.bonob.conf"
ports: ports:
- "{{ bonob_host_port }}:3000" - "{{ bonob.host_port }}:3000"
networks: networks:
- navidrome - navidrome
- default - default

View File

@ -0,0 +1,15 @@
{% if bonob.enabled %}
BNB_SONOS_AUTO_REGISTER={{ bonob.sonos.auto_register }}
BNB_SONOS_DEVICE_DISCOVERY={{ bonob.sonos.device_discovery }}
BNB_PORT=3000
{% if bonob.sonos.seed_host %}
BNB_SONOS_SEED_HOST={{ bonob.sonos.seed_host }}
{% endif %}
BNB_SUBSONIC_URL=http://navidrome:4533
BNB_SONOS_SERVICE_ID={{ bonob.sonos.service_id }}
BNB_URL=http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ bonob.host_port }}
BNB_SUBSONIC_CUSTOM_CLIENTS="audio/flac"
BNB_ICON_FOREGROUND_COLOR={{ bonob.icon_color }}
BNB_ICON_BACKGROUND_COLOR={{ bonob.icon_background }}
TZ={{ timezone }}
{% endif %}

View File

@ -0,0 +1,5 @@
TZ={{timezone}}
ND_ENABLETRANSCODINGCONFIG=true
ND_SCANSCHEDULE=1h
ND_LOGLEVEL=info
ND_SESSIONTIMEOUT=24h

6
test-requirements.txt Normal file
View File

@ -0,0 +1,6 @@
ansible==5.2.0
molecule==3.4.0
docker==5.0.0
molecule-docker==0.2.4
ansible-lint==5.3.2
yamllint==1.28.0