From 6d099061ac4fc25b0134ab72b06d07726b4ec86c Mon Sep 17 00:00:00 2001 From: Tuan-Dat Tran Date: Wed, 11 Dec 2024 19:58:57 +0100 Subject: [PATCH] feat(docker): Split docker compose to be deployed different services on different hosts. See host_vars of each host. Signed-off-by: Tuan-Dat Tran --- host_vars/docker-host00.yml | 16 ++++++++++ host_vars/docker-host02.yml | 26 ++++++++++++++++ production | 3 ++ roles/docker_host/tasks/deploy_compose.yml | 2 +- roles/docker_host/tasks/directory_setup.yml | 9 ------ .../compose.yaml.j2} | 30 +++++++++++++++++++ 6 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 host_vars/docker-host02.yml rename roles/docker_host/{files/compose.yaml => templates/compose.yaml.j2} (94%) diff --git a/host_vars/docker-host00.yml b/host_vars/docker-host00.yml index 154dc19..271a4f2 100644 --- a/host_vars/docker-host00.yml +++ b/host_vars/docker-host00.yml @@ -8,3 +8,19 @@ ansible_become_pass: "{{ vault.docker.host00.sudo }}" host: hostname: "docker-host00" ip: "{{ ansible_host }}" + +enable_nginx: true +enable_syncthing: true +enable_kuma: true +enable_plex: true +enable_arr: true +enable_prometheus: false +enable_grafana: false +enable_ddns_updater: true +enable_homeassistant: false +enable_stirling: true +enable_jellyfin: false +enable_paperless: true +enable_gitea: false +enable_changedetection: true +enable_calibre: false diff --git a/host_vars/docker-host02.yml b/host_vars/docker-host02.yml new file mode 100644 index 0000000..89c2c48 --- /dev/null +++ b/host_vars/docker-host02.yml @@ -0,0 +1,26 @@ +--- +ansible_user: "{{ user }}" +ansible_host: 192.168.20.36 +ansible_port: 22 +ansible_ssh_private_key_file: "{{ pk_path }}" +ansible_become_pass: "{{ vault.docker.host02.sudo }}" + +host: + hostname: "docker-host02" + ip: "{{ ansible_host }}" + +enable_nginx: true +enable_syncthing: false +enable_kuma: false +enable_plex: false +enable_arr: false +enable_prometheus: false +enable_grafana: false +enable_ddns_updater: false +enable_homeassistant: true +enable_stirling: false +enable_jellyfin: true +enable_paperless: false +enable_gitea: true +enable_changedetection: false +enable_calibre: false diff --git a/production b/production index 391cc79..be4494f 100644 --- a/production +++ b/production @@ -42,6 +42,7 @@ k3s-longhorn00 k3s-longhorn01 k3s-longhorn02 docker-host00 +docker-host02 [k3s_nodes] k3s-server00 @@ -65,9 +66,11 @@ ansible_ssh_common_args='-o ProxyCommand="ssh -p 22 -W %h:%p -q aya01"' [docker] docker-host00 +docker-host02 [docker_host] docker-host00 +docker-host02 [proxmox] aya01 diff --git a/roles/docker_host/tasks/deploy_compose.yml b/roles/docker_host/tasks/deploy_compose.yml index bda9960..dbe7297 100644 --- a/roles/docker_host/tasks/deploy_compose.yml +++ b/roles/docker_host/tasks/deploy_compose.yml @@ -1,7 +1,7 @@ --- - name: Copy docker compose file to target ansible.builtin.template: - src: "files/{{ item }}" + src: "templates/{{ item }}.j2" dest: "/opt/docker/compose/{{ item }}" owner: "{{ user }}" group: "{{ user }}" diff --git a/roles/docker_host/tasks/directory_setup.yml b/roles/docker_host/tasks/directory_setup.yml index 5846e41..18e7dab 100644 --- a/roles/docker_host/tasks/directory_setup.yml +++ b/roles/docker_host/tasks/directory_setup.yml @@ -97,12 +97,3 @@ opts: defaults,nolock state: mounted become: true - -- name: Ensure /opt/docker is mounted via NFS - ansible.posix.mount: - path: /opt/docker - src: 192.168.20.12:/opt/docker - fstype: nfs - opts: defaults,nolock - state: mounted - become: true diff --git a/roles/docker_host/files/compose.yaml b/roles/docker_host/templates/compose.yaml.j2 similarity index 94% rename from roles/docker_host/files/compose.yaml rename to roles/docker_host/templates/compose.yaml.j2 index d14c3fb..9989dc1 100644 --- a/roles/docker_host/files/compose.yaml +++ b/roles/docker_host/templates/compose.yaml.j2 @@ -1,4 +1,5 @@ services: +{% if enable_nginx %} nginx: container_name: "nginx" image: "jc21/nginx-proxy-manager:latest" @@ -13,7 +14,9 @@ services: - "/opt/docker/config/nginx/data:/data" - "/opt/docker/config/nginx/letsencrypt:/etc/letsencrypt" - "/var/run/docker.sock:/var/run/docker.sock" +{% endif %} +{% if enable_syncthing %} syncthing: image: syncthing/syncthing container_name: syncthing @@ -33,7 +36,9 @@ services: - PGID=1000 - TZ=Europe/Berlin hostname: syncthing +{% endif %} +{% if enable_kuma %} kuma: container_name: kuma image: louislam/uptime-kuma:1 @@ -50,7 +55,9 @@ services: - "3001:3001" volumes: - "/opt/local/kuma/:/app/data" +{% endif %} +{% if enable_plex %} plex: image: lscr.io/linuxserver/plex:latest container_name: plex @@ -80,7 +87,9 @@ services: - "/media/series:/tv:ro" - "/media/movies:/movies:ro" - "/media/songs:/music:ro" +{% endif %} +{% if enable_arr %} sonarr: image: lscr.io/linuxserver/sonarr:latest container_name: sonarr @@ -206,7 +215,9 @@ services: volumes: - /opt/docker/config/qbit/config:/config - /media/docker/data/arr_downloads:/downloads +{% endif %} +{% if enable_prometheus %} prometheus: image: prom/prometheus container_name: prometheus @@ -222,7 +233,9 @@ services: volumes: - /opt/docker/config/prometheus/:/etc/prometheus/ - prometheus_data:/prometheus/ +{% endif %} +{% if enable_grafana %} grafana: image: grafana/grafana-oss container_name: grafana @@ -239,7 +252,9 @@ services: volumes: - /media/docker/data/grafana/:/var/lib/grafana/ - /opt/docker/config/grafana/config/:/etc/grafana/ +{% endif %} +{% if enable_ddns_updater %} ddns-updater: container_name: ddns-updater image: "ghcr.io/qdm12/ddns-updater" @@ -250,7 +265,9 @@ services: net: {} volumes: - "/opt/docker/config/ddns-updater/data/:/updater/data/" +{% endif %} +{% if enable_homeassistant %} homeassistant: container_name: homeassistant image: "ghcr.io/home-assistant/home-assistant:stable" @@ -268,7 +285,9 @@ services: - 4357:4357 - 5683:5683 - 5683:5683/udp +{% endif %} +{% if enable_stirling %} stirling: container_name: stirling image: frooodle/s-pdf:latest @@ -277,7 +296,9 @@ services: - nginx networks: net: {} +{% endif %} +{% if enable_jellyfin %} jellyfin: container_name: jellyfin image: jellyfin/jellyfin @@ -296,7 +317,9 @@ services: - /media/songs:/music:ro ports: - "8096:8096" +{% endif %} +{% if enable_paperless %} paperless-broker: container_name: paperless-broker image: docker.io/library/redis:7 @@ -353,7 +376,9 @@ services: - "PAPERLESS_URL=https://paperless.docker-host00.lulu.seyshiro.de" - "PAPERLESS_TIME_ZONE=Europe/Berlin" - "PAPERLESS_OCR_LANGUAGE=deu" +{% endif %} +{% if enable_gitea %} git: container_name: git image: gitea/gitea:1.20.5-rootless @@ -373,7 +398,9 @@ services: environment: - USER_UID=1000 - USER_GID=1000 +{% endif %} +{% if enable_changedetection %} changedetection: container_name: changedetection image: dgtlmoon/changedetection.io @@ -384,7 +411,9 @@ services: - net volumes: - "/opt/docker/config/changedetection/data/:/datastore" +{% endif %} +{% if enable_calibre %} calibre: container_name: calibre image: lscr.io/linuxserver/calibre-web:latest @@ -401,6 +430,7 @@ services: volumes: - "/opt/local/calibre/:/config" - "/media/docker/data/calibre/:/books" +{% endif %} networks: net: