diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/README.md b/README.md index 613dbb7..945a574 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,46 @@ -# ansible-role-navidrome +# Ansible Role Navidrome -Ansible role to manage a Navidrome instance \ No newline at end of file +Ansible role to manage a [Navidrome](https://github.com/navidrome/navidrome) instance. + +## Installation + +Clone the repository in your local Ansible roles directory: + +``` +git clone https://git.riou.xyz/jriou/ansible-role-forgejo.git ~/.ansible/roles/navidrome +``` + +See [Storing and finding +roles](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#storing-and-finding-roles). + +## Configuration + +See [Variable +precedence](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#ansible-variable-precedence) +to find where you should put your own variables. + +See list of [default +variables](https://git.riou.xyz/jriou/ansible-role-navidrome/src/branch/main/defaults/main.yml). + +## Usage + +Example of a basic navidrome.yml playbook: + +```yaml +hosts: + - navidrome + +roles: + - navidrome +``` + +Then run the playbook: + +``` +ansible-playbook navidrome.yml +``` + +## Donate + +As we all love FOSS, you should consider sponsoring the +[Navidrome](https://github.com/navidrome/navidrome) project. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..478998b --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,14 @@ +--- +navidrome_version: 0.54.5 +navidrome_arch: amd64 +navidrome_user: navidrome +navidrome_group: navidrome +navidrome_music_folder: /opt/navidrome/music +navidrome_data_folder: /var/lib/navidrome +navidrome_cache_folder: "{{ navidrome_data_folder }}/cache" +navidrome_manage_iptables: false +navidrome_allowed_sources: [] +navidrome_address: localhost +navidrome_port: 4533 +navidrome_enable_insights_collector: false +# navidrome_base_url: diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..152799e --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,14 @@ +--- +- name: Reload systemd + ansible.builtin.systemd_service: + daemon_reload: true + +- name: Restart navidrome + ansible.builtin.service: + name: navidrome + state: restarted + +- name: Save iptables + ansible.builtin.command: + cmd: netfilter-persistent save + changed_when: true diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..d575f0e --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,62 @@ +--- +- name: Install package + ansible.builtin.apt: + deb: "https://github.com/navidrome/navidrome/releases/download/v{{ navidrome_version }}/navidrome_{{ navidrome_version }}_linux_{{ navidrome_arch }}.deb" + +- name: Create directories + ansible.builtin.file: + state: directory + path: "{{ item }}" + owner: "{{ navidrome_user }}" + group: "{{ navidrome_group }}" + mode: "0755" + loop: + - "{{ navidrome_music_folder }}" + - "{{ navidrome_data_folder }}" + - "{{ navidrome_cache_folder }}" + +- name: Create configuration file + ansible.builtin.template: + src: navidrome.toml.j2 + dest: /etc/navidrome/navidrome.toml + owner: "{{ navidrome_user }}" + group: "{{ navidrome_group }}" + mode: "0644" + notify: + - Restart navidrome + +- name: Create systemd override directory + ansible.builtin.file: + state: directory + path: /etc/systemd/system/navidrome.service.d + owner: root + group: root + mode: "0755" + +- name: Add systemd override + ansible.builtin.template: + src: override.conf.j2 + dest: /etc/systemd/system/navidrome.service.d/override.conf + owner: root + group: root + mode: "0755" + notify: + - Reload systemd + - Restart navidrome + +- name: Start service + ansible.builtin.service: + name: navidrome + state: started + +- name: Manage iptables + ansible.builtin.iptables: + chain: INPUT + protocol: tcp + source: "{{ item }}" + destination_port: "{{ navidrome_port }}" + jump: ACCEPT + comment: navidrome + loop: "{{ navidrome_allowed_sources }}" + notify: Save iptables + when: navidrome_manage_iptables diff --git a/templates/navidrome.toml.j2 b/templates/navidrome.toml.j2 new file mode 100644 index 0000000..2b6492b --- /dev/null +++ b/templates/navidrome.toml.j2 @@ -0,0 +1,10 @@ +{{ ansible_managed | comment }} +MusicFolder = "{{ navidrome_music_folder }}" +DataFolder = "{{ navidrome_data_folder }}" +CacheFolder = "{{ navidrome_cache_folder }}" +Address = "{{ navidrome_address }}" +Port = "{{ navidrome_port }}" +EnableInsightsCollector = "{{ navidrome_enable_insights_collector }}" +{% if navidrome_base_url is defined %} +BaseUrl = "{{ navidrome_base_url }}" +{% endif %} diff --git a/templates/override.conf.j2 b/templates/override.conf.j2 new file mode 100644 index 0000000..371ef28 --- /dev/null +++ b/templates/override.conf.j2 @@ -0,0 +1,5 @@ +{{ ansible_managed | comment }} +[Service] +User={{ navidrome_user }} +WorkingDirectory={{ navidrome_data_folder }} +ReadWritePaths={{ navidrome_data_folder }}