From a9d3003c68eaa1ec534d32164a296a4e8c648478 Mon Sep 17 00:00:00 2001 From: Klaus Schuetz Date: Fri, 9 Oct 2020 08:33:17 +0200 Subject: [PATCH] Make master.cf configurable, esure order of transport_maps lines in master.cf, Column service together with column type are uniq, so these two columns are used together as key. In that way, each default line of matser.cfcan be overwritten. When transport_maps is changed, lineinfile cant ensure, that the lines are in the right order. New lines were always added to the end of the file, and existing lines weren't changed. But the order of the lines is very important for this function. --- README.md | 15 ++++++++++ defaults/main.yml | 40 +++++++++++++++++++++++++ tasks/main.yml | 21 +++++++++---- templates/etc/postfix/master.cf.j2 | 5 ++++ templates/etc/postfix/transport_maps.j2 | 6 ++++ vars/main.yml | 1 + 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 templates/etc/postfix/master.cf.j2 create mode 100644 templates/etc/postfix/transport_maps.j2 diff --git a/README.md b/README.md index a5d0586..6e8352a 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ None * `postfix_smtpd_tls_cert_file` [default: `/etc/ssl/certs/ssl-cert-snakeoil.pem`]: Path to certificate file * `postfix_smtpd_tls_key_file` [default: `/etc/ssl/certs/ssl-cert-snakeoil.key`]: Path to key file * `postfix_raw_options` [default: `[]`]: List of lines (to pass extra (unsupported) configuration) + * `postfix_master_custom` [default: Debian default master.cf]: Dictionary of master.cf lines with service and type together as key, separated by space ## Dependencies @@ -229,6 +230,20 @@ A simple example that shows how to add some raw config: policyd-spf_time_limit = 3600 ``` +A simple example that shows how to disable bounce mails with master_custom: + +```yaml +--- +- hosts: all + roles: + - postfix + vars: + postfix_master_custom: + bounce unix: '- - y - 0 discard' + defer unix: '- - y - 0 discard' + trace unix: '- - y - 0 discard' +``` + #### License MIT diff --git a/defaults/main.yml b/defaults/main.yml index 35ab0df..8f4e66b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -45,3 +45,43 @@ postfix_default_database_type: hash postfix_smtpd_tls_cert_file: /etc/ssl/certs/ssl-cert-snakeoil.pem postfix_smtpd_tls_key_file: /etc/ssl/private/ssl-cert-snakeoil.key postfix_raw_options: [] +postfix_master_custom: [] +postfix_master_default: + smtp inet: 'n - y - - smtpd' + pickup unix: 'n - y 60 1 pickup' + cleanup unix: 'n - y - 0 cleanup' + qmgr unix: 'n - n 300 1 qmgr' + tlsmgr unix: '- - y 1000? 1 tlsmgr' + rewrite unix: '- - y - - trivial-rewrite' + bounce unix: '- - y - 0 bounce' + defer unix: '- - y - 0 bounce' + trace unix: '- - y - 0 bounce' + verify unix: '- - y - 1 verify' + flush unix: 'n - y 1000? 0 flush' + proxymap unix: '- - n - - proxymap' + proxywrite unix: '- - n - 1 proxymap' + smtp unix: '- - y - - smtp' + relay unix: '- - y - - smtp' + showq unix: 'n - y - - showq' + error unix: '- - y - - error' + retry unix: '- - y - - error' + discard unix: '- - y - - discard' + local unix: '- n n - - local' + virtual unix: '- n n - - virtual' + lmtp unix: '- - y - - lmtp' + anvil unix: '- - y - 1 anvil' + scache unix: '- - y - 1 scache' + maildrop unix: '- n n - - pipe + flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}' + uucp unix: '- n n - - pipe + flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)' + ifmail unix: '- n n - - pipe + flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)' + bsmtp unix: '- n n - - pipe + flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient' + scalemail-backend unix: '- n n - 2 pipe + flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}' + mailman unix: '- n n - - pipe + flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py + ${nexthop} ${user}' +postfix_master: "{{ postfix_master_default | combine(postfix_master_custom) }}" diff --git a/tasks/main.yml b/tasks/main.yml index 0f74727..8e4d5d6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -57,6 +57,19 @@ - postfix - postfix-configuration +- name: update mastercf file + template: + src: "{{ postfix_master_cf.lstrip('/') }}.j2" + dest: "{{ postfix_master_cf }}" + owner: root + group: root + mode: 0644 + notify: restart postfix + tags: + - configuration + - postfix + - postfix-configuration + - name: configure sasl username/password template: src: "{{ postfix_sasl_passwd_file.lstrip('/') }}.j2" @@ -163,16 +176,12 @@ - postfix-recipient-canonical-maps - name: configure transport maps - lineinfile: + template: dest: "{{ postfix_transport_maps_file }}" - regexp: '^{{ item.pattern | regex_escape }}.*' - line: '{{ item.pattern }} {{ item.result }}' + src: "{{ postfix_transport_maps_file.lstrip('/') }}.j2" owner: root group: root mode: 0644 - create: true - state: present - with_items: "{{ postfix_transport_maps }}" notify: - postmap transport_maps - restart postfix diff --git a/templates/etc/postfix/master.cf.j2 b/templates/etc/postfix/master.cf.j2 new file mode 100644 index 0000000..d919401 --- /dev/null +++ b/templates/etc/postfix/master.cf.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +{% for item in postfix_master %} +{{ item }} {{ postfix_master[item] }} +{% endfor %} diff --git a/templates/etc/postfix/transport_maps.j2 b/templates/etc/postfix/transport_maps.j2 new file mode 100644 index 0000000..1efd3f6 --- /dev/null +++ b/templates/etc/postfix/transport_maps.j2 @@ -0,0 +1,6 @@ +{{ ansible_managed | comment }} + +{% for transport in postfix_transport_maps %} +{{ transport.pattern }} {{ transport.result }} +{% endfor %} + diff --git a/vars/main.yml b/vars/main.yml index 050326f..1a4b650 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -7,6 +7,7 @@ postfix_debconf_selections: vtype: select postfix_main_cf: /etc/postfix/main.cf +postfix_master_cf: /etc/postfix/master.cf postfix_mailname_file: /etc/mailname postfix_aliases_file: /etc/aliases postfix_virtual_aliases_file: /etc/postfix/virtual