From 666f64d0ffb12526db72545ca3644f0f83d967d6 Mon Sep 17 00:00:00 2001 From: Hinrikus Wolf <mail@hinrikus-wolf.de> Date: Wed, 31 Jan 2018 23:14:12 +0100 Subject: [PATCH] postfix: test and fix virtual aliases --- postfix/files/dynamicmaps.cf | 2 -- postfix/handlers/main.yml | 6 ++++++ postfix/tasks/main.yml | 18 +++++++++++++++++- postfix/templates/aliases.j2 | 4 ++++ postfix/templates/main.cf.j2 | 11 ++++------- postfix/templates/v_aliases.j2 | 10 ++++++++++ 6 files changed, 41 insertions(+), 10 deletions(-) delete mode 100644 postfix/files/dynamicmaps.cf create mode 100644 postfix/templates/aliases.j2 create mode 100644 postfix/templates/v_aliases.j2 diff --git a/postfix/files/dynamicmaps.cf b/postfix/files/dynamicmaps.cf deleted file mode 100644 index b411db0..0000000 --- a/postfix/files/dynamicmaps.cf +++ /dev/null @@ -1,2 +0,0 @@ -sqlite postfix-sqlite.so dict_sqlite_open -pcre postfix-pcre.so dict_pcre_open diff --git a/postfix/handlers/main.yml b/postfix/handlers/main.yml index 4fa4978..e2fa640 100644 --- a/postfix/handlers/main.yml +++ b/postfix/handlers/main.yml @@ -3,3 +3,9 @@ - name: restart postfix service: name=postfix state=restarted +- name: postmap system + command: postalias cdb:/etc/aliases + +- name: postmap virtual + command: postmap cdb:/etc/postfix/virtual + diff --git a/postfix/tasks/main.yml b/postfix/tasks/main.yml index c884334..fad51fa 100644 --- a/postfix/tasks/main.yml +++ b/postfix/tasks/main.yml @@ -5,6 +5,7 @@ with_items: - postfix - postfix-pcre + - postfix-cdb tags: - postfix - mail @@ -12,7 +13,6 @@ - name: ensure not templated config is present copy: src=files/{{ item }} dest=/etc/postfix/ with_items: - - dynamicmaps.cf - login_maps.pcre - master.cf - sender_login_map.hash @@ -32,6 +32,22 @@ tags: - postfix - mail + +- name: ensure system alias database is present + template: src=templates/aliases.j2 dest=/etc/aliases + notify: + - postmap system + tags: + - postfix + - mail + +- name: ensure virtual alias database is present + template: src=templates/v_aliases.j2 dest=/etc/postfix/virtual + notify: + - postmap virtual + tags: + - postfix + - mail - meta: flush_handlers diff --git a/postfix/templates/aliases.j2 b/postfix/templates/aliases.j2 new file mode 100644 index 0000000..71ae0df --- /dev/null +++ b/postfix/templates/aliases.j2 @@ -0,0 +1,4 @@ +{% for alias in system_aliases %} +{{ alias.src }}:{{ alias.dest }} +{% endfor %} + diff --git a/postfix/templates/main.cf.j2 b/postfix/templates/main.cf.j2 index ad580a7..961d30f 100644 --- a/postfix/templates/main.cf.j2 +++ b/postfix/templates/main.cf.j2 @@ -39,8 +39,8 @@ smtpd_relay_restrictions = permit_sasl_authenticated defer_unauth_destination myhostname = {{ ansible_fqdn }} -alias_maps = hash:/etc/aliases -alias_database = hash:/etc/aliases +alias_maps = cdb:/etc/aliases +alias_database = cdb:/etc/aliases myorigin = /etc/mailname mydestination = $myhostname, localhost relayhost = @@ -50,16 +50,13 @@ recipient_delimiter = + inet_interfaces = all inet_protocols = all -virtual_mailbox_domains = $mydestination, wolfscloud.de +virtual_mailbox_domains = $mydestination, {{ virtual_domains | join(" ") }} virtual_mailbox_base = /var/vmail/ virtual_mailbox_limit = 512000000 virtual_minimum_uid = 5000 virtual_transport = lmtp:unix:private/dovecot-lmtp -#virtual_uid_maps = static:5000 virtual_gid_maps = static:5000 -#local_transport = virtual -virtual_alias_maps = hash:/etc/postfix/virtual -#smtpd_sender_login_maps = hash:/etc/postfix/sender_login_map +virtual_alias_maps = cdb:/etc/postfix/virtual smtpd_sender_login_maps = proxy:pcre:/etc/postfix/login_maps.pcre ################################################################################ diff --git a/postfix/templates/v_aliases.j2 b/postfix/templates/v_aliases.j2 new file mode 100644 index 0000000..c24df94 --- /dev/null +++ b/postfix/templates/v_aliases.j2 @@ -0,0 +1,10 @@ +{% for domain in virtual_domains %} +postmaster@{{ domain }} {{ adminaddr }} +hostmaster@{{ domain }} {{ adminaddr }} +abuse@{{ domain }} {{ adminaddr }} +{% endfor %} + +{% for alias in virtual_aliases %} +{{ alias.src }} {{ alias.dest }} +{% endfor %} + -- GitLab