From 2baaaa59e0f7708d0a8b61b432b5ffc8ac296412 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Fri, 25 Oct 2024 10:06:41 +0500 Subject: [PATCH] Make mail role generic --- mail.yml | 2 ++ roles/mail/meta/argument_specs.yml | 8 ++++++++ roles/mail/tasks/main.yml | 7 ++----- roles/mail/templates/maddy.conf.j2 | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mail.yml b/mail.yml index b556e90..92a2498 100644 --- a/mail.yml +++ b/mail.yml @@ -4,3 +4,5 @@ - role: mail users: "{{ mail_users }}" postgresql_url: postgres://maddy:{{ postgresql_users.maddy }}@postgresql:5432/maddy?sslmode=disable + domain: comfycamp.space + hostname: mail.comfycamp.space diff --git a/roles/mail/meta/argument_specs.yml b/roles/mail/meta/argument_specs.yml index 714ba95..4be43e3 100644 --- a/roles/mail/meta/argument_specs.yml +++ b/roles/mail/meta/argument_specs.yml @@ -8,3 +8,11 @@ argument_specs: users: type: dict default: {} + domain: + type: str + description: "example.com" + required: true + hostname: + type: str + description: "mx.example.com" + required: true diff --git a/roles/mail/tasks/main.yml b/roles/mail/tasks/main.yml index 89ef4e6..0f948cc 100644 --- a/roles/mail/tasks/main.yml +++ b/roles/mail/tasks/main.yml @@ -21,9 +21,6 @@ networks: - name: mail - name: postgresql - env: - MADDY_HOSTNAME: mail.comfycamp.space - MADDY_DOMAIN: comfycamp.space ports: - 25:25 - 143:143 @@ -32,8 +29,8 @@ - 993:993 volumes: - maddy:/data - - /etc/letsencrypt/live/comfycamp.space/fullchain.pem:/etc/tls/fullchain.pem:ro - - /etc/letsencrypt/live/comfycamp.space/privkey.pem:/etc/tls/privkey.pem:ro + - /etc/letsencrypt/live/{{ domain }}/fullchain.pem:/etc/tls/fullchain.pem:ro + - /etc/letsencrypt/live/{{ domain }}/privkey.pem:/etc/tls/privkey.pem:ro recreate: "{{ maddy_conf.changed }}" - name: Get users become: true diff --git a/roles/mail/templates/maddy.conf.j2 b/roles/mail/templates/maddy.conf.j2 index 8343bde..82a1e12 100644 --- a/roles/mail/templates/maddy.conf.j2 +++ b/roles/mail/templates/maddy.conf.j2 @@ -2,8 +2,8 @@ # Base variables -$(hostname) = {env:MADDY_HOSTNAME} -$(primary_domain) = {env:MADDY_DOMAIN} +$(hostname) = {{ hostname }} +$(primary_domain) = {{ domain }} $(local_domains) = $(primary_domain) # public private