From ae78c942d715b316f627085d9c55cbfb6d77dddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 5 Mar 2019 13:07:57 +0100 Subject: [PATCH] Use ansible_service to run mailu containers with docker compose. --- roles/docker/defaults/main.yml | 2 + roles/docker/tasks/services/mailu.yml | 201 ++++++++++++++------------ 2 files changed, 114 insertions(+), 89 deletions(-) diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml index 295631b..c23d87e 100644 --- a/roles/docker/defaults/main.yml +++ b/roles/docker/defaults/main.yml @@ -50,4 +50,6 @@ cryptohagen_website: domain: "cryptohagen.dk" mailu: + domain: "mail.{{ base_domain }}" + dns: 192.168.203.254 subnet: 192.168.203.0/24 diff --git a/roles/docker/tasks/services/mailu.yml b/roles/docker/tasks/services/mailu.yml index d9af652..a593e8b 100644 --- a/roles/docker/tasks/services/mailu.yml +++ b/roles/docker/tasks/services/mailu.yml @@ -1,11 +1,5 @@ --- -- name: setup network for mailu - docker_network: - name: mailu - ipam_options: - subnet: "{{ mailu.subnet }}" - - name: create mailu volume folders file: name: "{{ mailu.volume_folder }}/{{ volume }}" @@ -23,99 +17,128 @@ loop_control: loop_var: volume -- name: mailu redis container - docker_container: - name: mailu_redis - image: redis:alpine - restart_policy: always - volumes: - - "{{ mailu.volume_folder }}/redis:/data" - -- name: mailu database container - docker_container: - image: mailu/postgresql:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder }}/data/psql_db:/data" - - "{{ mailu.volume_folder }}/data/psql_backup:/backup" - - name: upload mailu.env file template: src: mailu.env.j2 dest: "{{ mailu.volume_folder}}/mailu.env" -- name: mailu front container - docker_container: - name: mailu_front - image: mailu/nginx:1.6 - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder }}/certs:/certs" - - "{{ mailu.volume_folder }}/overrides/nginx:/overrides" +- name: run mail server containers + docker_service: + project_name: mail_server + pull: yes + definition: + version: '3.6' + services: + redis: + image: redis:alpine + restart: always + volumes: + - "{{ mailu.volume_folder }}/redis:/data" -- name: mailu admin container - docker_container: - image: mailu/admin:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/data:/data" - - "{{ mailu.volume_folder}}/dkim:/dkim" + postgresql: + image: mailu/postgresql:1.6 + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/data/psql_db:/data" + - "{{ mailu.volume_folder }}/data/psql_backup:/backup" + networks: + - name: mailu -- name: mailu imap container - docker_container: - image: mailu/dovecot:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/mail:/mail" - - "{{ mailu.volume_folder}}/overrides:/overrides" + front: + image: mailu/nginx:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + environment: + VIRTUAL_HOST: "{{ mailu.domain }}" + LETSENCRYPT_HOST: "{{ mailu.domain }}" + LETSENCRYPT_EMAIL: "{{ letsencrypt_email }}" + volumes: + - "{{ mailu.volume_folder }}/certs:/certs" + - "{{ mailu.volume_folder }}/overrides/nginx:/overrides" + expose: + - "80" + ports: + - "993:993" + - "25:25" + - "587:587" + networks: + - default + - external_services -- name: mailu smtp container - docker_container: - image: mailu/postfix:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/overrides:/overrides" + resolver: + image: mailu/unbound:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + networks: + default: + ipv4_address: "{{ mailu.dns }}" -- name: mailu antispam container - docker_container: - image: mailu/rspamd:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/filter:/var/lib/rspamd" - - "{{ mailu.volume_folder}}/dkim:/dkim" - - "{{ mailu.volume_folder}}/overrides/rspamd:/etc/rspamd/override.d" + admin: + image: mailu/admin:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/data:/data" + - "{{ mailu.volume_folder }}/dkim:/dkim" + depends_on: + - redis -- name: mailu antivirus container - docker_container: - image: mailu/clamav:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/filter:/data" + imap: + image: mailu/dovecot:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/mail:/mail" + - "{{ mailu.volume_folder }}/overrides:/overrides" + depends_on: + - front -- name: mailu webdav container - docker_container: - image: mailu/radicale:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder}}/dav:/data" + smtp: + image: mailu/postfix:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/overrides:/overrides" + depends_on: + - front + - resolver + dns: + - "{{ mailu.dns }}" -- name: mailu fetchmail container - docker_container: - image: mailu/fetchmail:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" + antispam: + image: mailu/rspamd:{{ mail_server_mailu_version }} + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/filter:/var/lib/rspamd" + - "{{ mailu.volume_folder }}/dkim:/dkim" + - "{{ mailu.volume_folder }}/overrides/rspamd:/etc/rspamd/override.d" + depends_on: + - front + - resolver + dns: + - "{{ mailu.dns }}" -- name: mailu webmail container - docker_container: - image: mailu/rainloop:1.6 - restart_policy: always - env_file: "{{ mailu.volume_folder}}/mailu.env" - volumes: - - "{{ mailu.volume_folder }}/webmail:/data" + webmail: + image: mailu/rainloop:1.6 + restart: always + env_file: "{{ mailu.volume_folder}}/mailu.env" + volumes: + - "{{ mailu.volume_folder }}/webmail:/data" + depends_on: + - front + - resolver + dns: + - "{{ mailu.dns }}" + + networks: + default: + driver: bridge + ipam: + driver: default + config: + - subnet: "{{ mailu.subnet }}" + external_services: + external: + name: external_services