diff --git a/.env.yml b/.env.yml new file mode 100644 index 0000000..7aff983 --- /dev/null +++ b/.env.yml @@ -0,0 +1 @@ +bonob.enabled: "true" \ No newline at end of file diff --git a/.gitignore b/.gitignore index bcb54e9..f98084c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,14 @@ -*.retry -*/__pycache__ -*.pyc +tests/playbook.retry +tests/.cache +__pycache__ +.pytest_cache +.molecule .cache .venv -.env.yml -docker-compose.yml \ No newline at end of file + +*.iml +.idea +.project + +*.pyc +**/.vscode diff --git a/README.md b/README.md index 262f0f8..948d4ea 100644 --- a/README.md +++ b/README.md @@ -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: ```yaml -navidrome_image_version: 'latest' +navidrome.image_version: 'latest' ``` Navidrome needs a place to store its configuration and another to pick up music from: ```yaml -navidrome_config_volume: '/mnt/config-local/navidrome' -navidrome_music_volume: '/mnt/music' +navidrome.config_volume: '/mnt/config-local/navidrome' +navidrome.music_volume: '/mnt/music' ``` 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: ```yaml -navidrome_host_port: 48533 +navidrome.host_port: 48533 ``` ### 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 -bonob_enabled: false +bonob.enabled: false ``` You can also specify the bonob image version and the port at which is available: ```yml -bonob_image_version: 'latest' -bonob_host_port: 48534 +bonob.image_version: 'latest' +bonob.host_port: 48534 ``` You can change the colors of the bonob icon displayed: ```yml -bonob_icon_color: "beige" -bonob_icon_background: "red" +bonob.icon_color: "beige" +bonob.icon_background: "red" ``` #### Sonos The sonos-related variables are: ```yml -bonob_sonos_auto_register: 'true' -bonob_sonos_device_discovery: 'true' -bonob_sonos_seed_host: -bonob_sonos_service_id: "246" +bonob.sonos.auto_register: 'true' +bonob.sonos.device_discovery: 'true' +bonob.sonos.seed_host: +bonob.sonos.service_id: "246" ``` If you try sonos autodiscovery and it doesn't work, please: 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 You can also add custom clients for streaming: ```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). @@ -97,7 +97,7 @@ A list of other roles hosted on Galaxy should go here, plus any details in regar - name: Example playbook hosts: services vars: - bonob_enabled: "true" + bonob.enabled: "true" roles: - 'laurivan.navidrome' diff --git a/defaults/main.yml b/defaults/main.yml index 8dd1777..1989c2c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,27 +1,37 @@ --- # defaults file for navidrome -navidrome_image_version: 'latest' - -navidrome_config_volume: '/mnt/config-local/navidrome' +navidrome_root_path: /var/local/navidrome +navidrome_config_volume: "{{ navidrome_root_path }}/config" +navidrome_docker_path: "{{ navidrome_root_path }}/docker" navidrome_music_volume: '/mnt/music' -navidrome_host_port: 48533 +navidrome_skeleton_paths: + - "{{ navidrome_docker_path }}" + - "{{ navidrome_config_volume }}" timezone: 'Europe/Brussels' -# Bonob -bonob_enabled: false -bonob_image_version: 'latest' -bonob_host_port: 48534 -bonob_icon_color: "beige" -bonob_icon_background: "red" +navidrome: + image_version: 'latest' + host_port: 48533 -## Bonob sonos settings -bonob_sonos_auto_register: 'true' -bonob_sonos_device_discovery: 'true' -bonob_sonos_seed_host: -bonob_sonos_service_id: "246" + +# Bonob +bonob: + enabled: false + 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 -bonob_subsonic_custom_clients: 'audio/flac' + subsonic: + custom_clients: 'audio/flac' diff --git a/tasks/config.yml b/tasks/config.yml new file mode 100644 index 0000000..a35919e --- /dev/null +++ b/tasks/config.yml @@ -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 + + \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..004503a --- /dev/null +++ b/tasks/install.yml @@ -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 \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 69c174b..d6fded0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,54 +1,11 @@ --- -# tasks file for navidrome -- name: 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_config_volume }}" - - "~/navidrome" +- name: "NAVIDROME | Configure" + import_tasks: config.yml tags: - - configuration - become: true + - navidrome.configure -- name: Check if the music volume exists - ansible.builtin.stat: - path: "{{ navidrome_music_volume }}" - register: music +- name: "NAVIDROME | Install" + import_tasks: install.yml tags: - - configuration - -- 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 \ No newline at end of file + - navidrome.install diff --git a/templates/env.bonob.conf.j2 b/templates/env.bonob.conf.j2 deleted file mode 100644 index 3c1603d..0000000 --- a/templates/env.bonob.conf.j2 +++ /dev/null @@ -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 %} diff --git a/templates/env.navidrome.conf.j2 b/templates/env.navidrome.conf.j2 deleted file mode 100644 index 8c92d95..0000000 --- a/templates/env.navidrome.conf.j2 +++ /dev/null @@ -1 +0,0 @@ -TZ={{timezone}} \ No newline at end of file diff --git a/templates/docker-compose.yml.j2 b/templates/navidrome/docker-compose.yml.j2 similarity index 51% rename from templates/docker-compose.yml.j2 rename to templates/navidrome/docker-compose.yml.j2 index fa690dd..3969c80 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/navidrome/docker-compose.yml.j2 @@ -1,27 +1,28 @@ version: "3.3" services: navidrome: - image: "deluan/navidrome:{{ navidrome_image_version }}" + image: "deluan/navidrome:{{ navidrome.image_version }}" restart: always env_file: - - ~/navidrome/env.navidrome.conf + - "{{ navidrome_docker_path | expanduser | realpath }}/env.navidrome.conf" volumes: - {{ navidrome_config_volume }}:/data - {{ navidrome_music_volume }}:/music:ro ports: - - {{ navidrome_host_port }}:4533 + - {{ navidrome.host_port }}:4533 networks: - navidrome -{% if bonob_enabled %} + +{% if bonob.enabled %} bonob: - image: simojenki/bonob:{{ bonob_image_version }} + image: simojenki/bonob:{{ bonob.image_version }} restart: always depends_on: - navidrome env_file: - - ~/navidrome/env.bonob.conf + - "{{ navidrome_docker_path | expanduser | realpath }}/env.bonob.conf" ports: - - "{{ bonob_host_port }}:3000" + - "{{ bonob.host_port }}:3000" networks: - navidrome - default diff --git a/templates/navidrome/env.bonob.conf.j2 b/templates/navidrome/env.bonob.conf.j2 new file mode 100644 index 0000000..a951c36 --- /dev/null +++ b/templates/navidrome/env.bonob.conf.j2 @@ -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 %} diff --git a/templates/navidrome/env.navidrome.conf.j2 b/templates/navidrome/env.navidrome.conf.j2 new file mode 100644 index 0000000..bd54cee --- /dev/null +++ b/templates/navidrome/env.navidrome.conf.j2 @@ -0,0 +1,5 @@ +TZ={{timezone}} +ND_ENABLETRANSCODINGCONFIG=true +ND_SCANSCHEDULE=1h +ND_LOGLEVEL=info +ND_SESSIONTIMEOUT=24h \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..5a6e7d0 --- /dev/null +++ b/test-requirements.txt @@ -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 \ No newline at end of file