From ca36ac0701335735c7fca1290ba202d210f2ecb6 Mon Sep 17 00:00:00 2001 From: David Stephens Date: Sun, 28 Aug 2022 16:43:58 +0100 Subject: [PATCH] Booksonic starts and stops --- nas.yml | 1 - roles/booksonic/defaults/main.yml | 3 ++ roles/booksonic/handlers/main.yml | 9 ++++ roles/booksonic/tasks/main.yml | 69 ++++++++++++++++--------------- 4 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 roles/booksonic/handlers/main.yml diff --git a/nas.yml b/nas.yml index e8dc5ab9..8af29925 100644 --- a/nas.yml +++ b/nas.yml @@ -56,7 +56,6 @@ - role: booksonic tags: - booksonic - when: (booksonic_enabled | default(False)) - role: calibre tags: diff --git a/roles/booksonic/defaults/main.yml b/roles/booksonic/defaults/main.yml index 6b0bdb7f..33ba10fd 100644 --- a/roles/booksonic/defaults/main.yml +++ b/roles/booksonic/defaults/main.yml @@ -17,3 +17,6 @@ booksonic_hostname: "booksonic" # specs booksonic_memory: 1g + +# docker +booksonic_container_name: booksonic diff --git a/roles/booksonic/handlers/main.yml b/roles/booksonic/handlers/main.yml new file mode 100644 index 00000000..ae6bd79c --- /dev/null +++ b/roles/booksonic/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Stop Booksonic + docker_container: + name: "{{ booksonic_container_name }}" + state: absent + when: booksonic_enabled is false + listen: + - "stop booksonic" + - "stop disabled applications" diff --git a/roles/booksonic/tasks/main.yml b/roles/booksonic/tasks/main.yml index 9db66328..f419684a 100644 --- a/roles/booksonic/tasks/main.yml +++ b/roles/booksonic/tasks/main.yml @@ -1,35 +1,38 @@ --- -- name: Create Booksonic Directories - file: - path: "{{ item }}" - state: directory - mode: 0755 - with_items: - - "{{ booksonic_data_directory }}/data" - - "{{ booksonic_data_directory }}/playlists" +- name: Booksonic + block: + - name: Create Booksonic Directories + file: + path: "{{ item }}" + state: directory + mode: 0755 + with_items: + - "{{ booksonic_data_directory }}/data" + - "{{ booksonic_data_directory }}/playlists" -- name: Booksonic Docker Container - docker_container: - name: booksonic - image: linuxserver/booksonic-air:latest - pull: true - volumes: - - "{{ booksonic_data_directory }}/data:/booksonic/data:rw" - - "{{ booksonic_data_directory }}/playlists:/booksonic/playlists:rw" - - "{{ booksonic_audiobooks_directory }}:/booksonic/audiobooks:rw" - - "{{ booksonic_podcasts_directory }}:/booksonic/podcasts:rw" - ports: - - "{{ booksonic_port }}:4040" - env: - TZ: "{{ ansible_nas_timezone }}" - PUID: "{{ booksonic_user_id }}" - PGID: "{{ booksonic_group_id }}" - restart_policy: unless-stopped - memory: "{{ booksonic_memory }}" - labels: - traefik.enable: "{{ booksonic_available_externally | string }}" - traefik.http.routers.booksonic.rule: "Host(`{{ booksonic_hostname }}.{{ ansible_nas_domain }}`)" - traefik.http.routers.booksonic.tls.certresolver: "letsencrypt" - traefik.http.routers.booksonic.tls.domains[0].main: "{{ ansible_nas_domain }}" - traefik.http.routers.booksonic.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" - traefik.http.services.booksonic.loadbalancer.server.port: "4040" + - name: Booksonic Docker Container + docker_container: + name: "{{ booksonic_container_name }}" + image: linuxserver/booksonic-air:latest + pull: true + volumes: + - "{{ booksonic_data_directory }}/data:/booksonic/data:rw" + - "{{ booksonic_data_directory }}/playlists:/booksonic/playlists:rw" + - "{{ booksonic_audiobooks_directory }}:/booksonic/audiobooks:rw" + - "{{ booksonic_podcasts_directory }}:/booksonic/podcasts:rw" + ports: + - "{{ booksonic_port }}:4040" + env: + TZ: "{{ ansible_nas_timezone }}" + PUID: "{{ booksonic_user_id }}" + PGID: "{{ booksonic_group_id }}" + restart_policy: unless-stopped + memory: "{{ booksonic_memory }}" + labels: + traefik.enable: "{{ booksonic_available_externally | string }}" + traefik.http.routers.booksonic.rule: "Host(`{{ booksonic_hostname }}.{{ ansible_nas_domain }}`)" + traefik.http.routers.booksonic.tls.certresolver: "letsencrypt" + traefik.http.routers.booksonic.tls.domains[0].main: "{{ ansible_nas_domain }}" + traefik.http.routers.booksonic.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" + traefik.http.services.booksonic.loadbalancer.server.port: "4040" + when: booksonic_enabled is true