infra/roles/owntone/tasks/main.yml

295 lines
6.7 KiB
YAML

---
- name: create OwnTone directories
file:
state: directory
path: "{{ item.path }}"
mode: "{{ item.mode | default('0750') }}"
owner: "{{ owntone_user.uid }}"
group: "{{ owntone_group.gid }}"
tags:
- owntone-dirs
loop_control:
label: "{{ item.path }}"
with_items:
- path: /var/cache/owntone
mode: "0755"
- path: /srv/owntone
- path: /srv/owntone/db
- path: /srv/owntone/fifo
- name: Create OwnTone log directory (if needed)
file:
state: directory
path: "{{ owntone_log_dir }}"
mode: "0750"
owner: "{{ owntone_user.uid }}"
group: "root"
tags:
- owntone-dirs
when: owntone_log_dir != "/var/log"
- name: remove default log file (if it is not going to be used)
file:
state: absent
path: /var/log/owntone.log
when: owntone_log_dir != "/var/log"
- name: ensure '{{ audio_dir }}' exists
file:
state: directory
path: "{{ audio_dir }}"
mode: "0750"
owner: "{{ owntone_user.uid }}"
group: "{{ owntone_group.gid }}"
tags:
- owntone-dirs
- name: ensure subdirs exist in '{{ audio_dir }}'
file:
state: directory
path: "{{ audio_dir }}/{{ item.name }}"
mode: "{{ item.mode | default('0750') }}"
owner: "{{ owntone_user.uid }}"
group: "{{ owntone_group.gid }}"
tags:
- owntone-dirs
loop_control:
label: "{{ audio_dir }}/{{ item.name }}"
with_items:
- name: audiobooks
- name: podcasts
- name: music
- name: playlists
- name: local
- name: local/music
- name: local/compilations
- name: copy playlists
copy:
src: "playlists/{{ item }}/"
dest: "{{ audio_dir }}//playlists/{{ item }}/"
owner: "{{ owntone_user.uid }}"
group: "{{ owntone_user.gid }}"
directory_mode: "0750"
mode: "0640"
loop_control:
label: "{{ item }}"
with_items:
- SomaFM
tags:
- owntone-playlists
- owntone-radio
- name: create input pipe
command:
cmd: mkfifo "/srv/owntone/fifo/{{ item.filename }}"
creates: "/srv/owntone/fifo/{{ item.filename }}"
become_user: "{{ owntone_user.username }}"
loop_control:
label: "{{ item }}"
with_items: "{{ owntone_fifo }}"
tags:
- owntone-fifo
- name: install certs
copy:
src: "/usr/local/etc/letsencrypt/live/{{ item }}"
dest: "/usr/local/etc/certs/"
owner: root
group: root
mode: 0755
tags:
- letsencrypt-certs
notify: reload nginx
vars:
prediff_cmd: echo
with_items:
- "{{ domain }}"
- name: template nginx vhost
template:
src: 01-owntone.conf.j2
dest: /etc/nginx/sites-enabled/01-owntone.conf
owner: root
group: root
mode: 0644
tags:
- nginx
- owntone-nginx
notify: reload nginx
- name: template logrotate config for '{{ owntone_log_dir }}' (not /var/log)
template:
src: logrotate.d/owntone.j2
dest: /etc/logrotate.d/owntone
owner: root
group: root
mode: 0644
tags:
- logrotate
- owntone-logrotate
notify:
- restart logrotate.service
when: owntone_log_dir != "/var/log"
- name: ensure no logrotate config, since owntone is logging to '/var/log' (not a subdir)
file:
state: absent
path: /etc/logrotate.d/owntone
tags:
- logrotate
- owntone-logrotate
notify:
- restart logrotate.service
when: owntone_log_dir == "/var/log"
- name: template config file
template:
src: owntone.conf.j2
dest: "/etc/owntone.conf"
owner: "{{ owntone_user.uid }}"
group: "{{ owntone_group.gid }}"
mode: 0644
notify:
- restart owntone.service
- restart owntone container
tags:
- owntone.conf
- name: systemd unit file
template:
src: owntone.service.j2
dest: /etc/systemd/system/owntone.service
owner: root
group: root
mode: "0644"
tags:
- systemd
- owntone-systemd
notify: systemctl daemon-reload
- name: rescan script for cronjob
template:
src: "{{ item }}.j2"
dest: /usr/local/bin/{{ item }}
owner: root
group: root
mode: 0755
tags:
- cron
- owntone-cron
with_items:
- owntone-trigger-rescan.sh
- name: cron file
template:
src: cron/owntone.j2
dest: /etc/cron.d/owntone
owner: root
group: root
mode: 0600
tags:
- cron
- owntone-cron
- name: fuse allow other
lineinfile:
path: /etc/fuse.conf
line: user_allow_other
state: present
when: owntone_ssh_mounts|default(false)
- name: install owntone
when: not owntone_docker
apt:
name:
- owntone-server
update_cache: true
state: latest
tags:
- owntone-packages
- owntone-apt
- packages
- name: enable owntone service and ensure '{{ owntone_state }}' state
when: not owntone_docker
service:
name: owntone
state: "{{ owntone_state }}"
enabled: true
tags:
- systemd
- owntone-systemd
register: owntone_service
- name: OwnTone container in '{{ owntone_state }}' state
when: owntone_docker == true
docker_container:
name: owntone
#image: git.sudo.is/ben/owntone:latest
#image: git.sudo.is/ben/owntone:file-scan-dir-path
image: git.sudo.is/ben/owntone-server:latest
detach: true
pull: true
auto_remove: false
restart_policy: "unless-stopped"
state: "{{ owntone_state }}"
container_default_behavior: compatibility
networks_cli_compatible: false
# not needed, owntone drop privileges to {{ owntone_user }}, set in owntone.conf
user: "{{ owntone_user.uid }}:{{ owntone_group.gid }}"
network_mode: host
privileged: false
security_opts: "apparmor=unconfined"
# network_mode: bridgewithdns
# networks:
# - name: bridgewithdns
# ipv4_address: "{{ bridgewithdns.owntone }}"
env:
VITE_OWNTONE_URL: "https://{{ owntone_url }}"
mounts:
- type: bind
source: /run/dbus
target: /run/dbus
- type: bind
source: /run/avahi-daemon/socket
target: /run/avahi-daemon/socket
- type: bind
source: "/etc/owntone.conf"
target: "/etc/owntone.conf"
- type: bind
source: "/srv/owntone"
target: "/srv/owntone"
- type: bind
source: "/var/cache/owntone"
target: "/var/cache/owntone"
- type: bind
source: "/var/log/owntone"
target: "/var/log/owntone"
- type: bind
source: "{{ audio_dir }}/podcasts"
target: "{{ audio_dir }}/podcasts"
tags:
- owntone-container
- docker-containers
- name: stop and disable owntone service if running in docker
when: owntone_docker == true
service:
name: owntone
state: stopped
enabled: false
tags:
- systemd
- name: stop owntone container if running as service
docker_container:
name: owntone
state: stopped
ignore_errors: true
when:
- not owntone_docker
- false