From 6a0b4c57b53e9cf58cf952f90c6ec6e3ac97fa7a Mon Sep 17 00:00:00 2001 From: David Stephens Date: Sun, 28 Aug 2022 17:00:31 +0100 Subject: [PATCH] Cloudcmd starts and stops --- nas.yml | 1 - roles/cloudcmd/defaults/main.yml | 3 ++ roles/cloudcmd/handlers/main.yml | 9 +++++ roles/cloudcmd/tasks/main.yml | 61 +++++++++++++++++--------------- 4 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 roles/cloudcmd/handlers/main.yml diff --git a/nas.yml b/nas.yml index 6b0d595a..230e5edf 100644 --- a/nas.yml +++ b/nas.yml @@ -64,7 +64,6 @@ - role: cloudcmd tags: - cloudcmd - when: (cloudcmd_enabled | default(False)) - role: cloudflare_ddns tags: diff --git a/roles/cloudcmd/defaults/main.yml b/roles/cloudcmd/defaults/main.yml index 74f8361f..393fd6ba 100644 --- a/roles/cloudcmd/defaults/main.yml +++ b/roles/cloudcmd/defaults/main.yml @@ -17,3 +17,6 @@ cloudcmd_port: "7373" # specs cloudcmd_memory: "1g" + +# docker +cloudcmd_container_name: cloudcmd diff --git a/roles/cloudcmd/handlers/main.yml b/roles/cloudcmd/handlers/main.yml new file mode 100644 index 00000000..fa524b72 --- /dev/null +++ b/roles/cloudcmd/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Stop Cloudcmd + docker_container: + name: "{{ cloudcmd_container_name }}" + state: absent + when: cloudcmd_enabled is false + listen: + - "stop cloudcmd" + - "stop disabled applications" diff --git a/roles/cloudcmd/tasks/main.yml b/roles/cloudcmd/tasks/main.yml index 0c999986..ad0bb8c9 100644 --- a/roles/cloudcmd/tasks/main.yml +++ b/roles/cloudcmd/tasks/main.yml @@ -1,31 +1,34 @@ --- -- name: Create Cloudcmd Directories - file: - path: "{{ item }}" - state: directory - with_items: - - "{{ cloudcmd_data_directory }}" +- name: Cloudcmd + block: + - name: Create Cloudcmd Directories + file: + path: "{{ item }}" + state: directory + with_items: + - "{{ cloudcmd_data_directory }}" -- name: Create Cloudcmd Docker Container - docker_container: - name: cloudcmd - image: coderaiser/cloudcmd - pull: true - volumes: - - "{{ cloudcmd_data_directory }}:/config:rw" - - "{{ cloudcmd_browse_directory }}:/mnt/fs" - ports: - - "{{ cloudcmd_port }}:8000" - env: - TZ: "{{ ansible_nas_timezone }}" - PUID: "{{ cloudcmd_user_id }}" - PGID: "{{ cloudcmd_group_id }}" - restart_policy: unless-stopped - memory: "{{ cloudcmd_memory }}" - labels: - traefik.enable: "{{ cloudcmd_available_externally | string }}" - traefik.http.routers.cloudcmd.rule: "Host(`{{ cloudcmd_hostname }}.{{ ansible_nas_domain }}`)" - traefik.http.routers.cloudcmd.tls.certresolver: "letsencrypt" - traefik.http.routers.cloudcmd.tls.domains[0].main: "{{ ansible_nas_domain }}" - traefik.http.routers.cloudcmd.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" - traefik.http.services.cloudcmd.loadbalancer.server.port: "8000" + - name: Create Cloudcmd Docker Container + docker_container: + name: "{{ cloudcmd_container_name }}" + image: coderaiser/cloudcmd + pull: true + volumes: + - "{{ cloudcmd_data_directory }}:/config:rw" + - "{{ cloudcmd_browse_directory }}:/mnt/fs" + ports: + - "{{ cloudcmd_port }}:8000" + env: + TZ: "{{ ansible_nas_timezone }}" + PUID: "{{ cloudcmd_user_id }}" + PGID: "{{ cloudcmd_group_id }}" + restart_policy: unless-stopped + memory: "{{ cloudcmd_memory }}" + labels: + traefik.enable: "{{ cloudcmd_available_externally | string }}" + traefik.http.routers.cloudcmd.rule: "Host(`{{ cloudcmd_hostname }}.{{ ansible_nas_domain }}`)" + traefik.http.routers.cloudcmd.tls.certresolver: "letsencrypt" + traefik.http.routers.cloudcmd.tls.domains[0].main: "{{ ansible_nas_domain }}" + traefik.http.routers.cloudcmd.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" + traefik.http.services.cloudcmd.loadbalancer.server.port: "8000" + when: cloudcmd_enabled is true