diff --git a/defaults/main.yml b/defaults/main.yml index bc24882e0a964078cf450bd5b35d50bfe1a4dc54..d26ce0bdbf91d65bd06975e16a293682342c50ae 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,6 +2,28 @@ # The name of this mail system, set in '/etc/mailname' postfix__mailname: '{{ ansible_fqdn }}' +# These dictionaries build the lookup tables with the corresponding name. So +# postfix__tables.transport is used to build the transport lookup table, +# postfix__tables.sasl_passwd is used to build the SASL password map table, etc. +# Within each dictionary the 'key' is the lookup pattern and the 'value' is the +# returned value. +# +# For example, this postfix__tables.transport example: +# +# postfix__tables: +# transport: +# 'codingallnight.com': ':' +# '*': 'discard:' +# +# would result in the following transport table: +# +# codingallnight.com : +# * discard: +# +postfix__tables: + sasl_passwd: {} + transport: {} + # Default variables for the main.cf template. These are always included. @@ -28,44 +50,5 @@ postfix__mailbox_size_limit: 0 postfix__recipient_delimiter: '+' postfix__inet_interfaces: all postfix__inet_protocols: all - - - -# Transport map -# <pattern> is an email address, domain name, or * to lookup the mail recipient -# <result> specificies how and where to deliver mail and has the format -# <transport>:<nexthop>. Both <transport> and <nexthop> are optional, -# but the delimiting ':' is required. -# -# EXAMPLES: -# -# This configuration will pass mail for the domain 'internal.domain.com' without -# modifying it, while discard all mail addressed to other recipient domains. -# -# postfix__transport_map: -# - { pattern: 'internal.domain.com', result: ':' } -# - { pattern: '*', result: 'discard:' } -# -# -# This configuration will discard mail sent to localhost and will relay all -# other mail through Mailgun. -# -# postfix__transport_map: -# - { pattern: 'localhost', result: 'discard:' } -# - { pattern: 'localhost.localdomain', result: 'discard:' } -# - { pattern: '*', result: 'relay:[smtp.mailgun.org]:587' } -# -# -# Valid <transport> and <nexthop> values are described in the postfix transport -# documentation. http://www.postfix.org/transport.5.html -postfix__transport_map: [] - - - -# SASL Password Maps -postfix__smtp_sasl_password_map: [] -postfix__smtp_sasl_auth_enable: yes -postfix__smtp_sasl_security_options: noanonymous -postfix__smtp_sasl_tls_security_options: '{{ postfix__smtp_sasl_security_options }}' ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/tasks/main.yml b/tasks/main.yml index 31bb81b3f21192183611fd08edbfd6b010e8fb96..a339487ac3dacf3ac4cfcee194580ee75d9c4b61 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,24 +26,26 @@ group: root mode: 0644 -- name: Generate Postfix sasl_passwd map +- name: Create the SASL password lookup table template: - src: templates/sasl_passwd.in.j2 + src: lookup_table.j2 dest: /etc/postfix/sasl_passwd.in owner: root group: root mode: 0600 - when: postfix__smtp_sasl_password_map + vars: + table: '{{ postfix__tables.sasl_passwd }}' notify: ['make postfix sasl_passwd.db'] -- name: Generate Postfix transport map +- name: Create the transport lookup table template: - src: templates/transport.in.j2 + src: lookup_table.j2 dest: /etc/postfix/transport.in owner: root group: root mode: 0644 - when: postfix__transport_map + vars: + table: '{{ postfix__tables.transport }}' notify: ['make postfix transport.db'] ... # vi: set ts=2 sts=2 sw=2 et ft=yaml: diff --git a/templates/lookup_table.j2 b/templates/lookup_table.j2 new file mode 100644 index 0000000000000000000000000000000000000000..43d3c79bed5d2fc0d9cc3cb6b47deaf90d2823c2 --- /dev/null +++ b/templates/lookup_table.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +{% for key, value in table.items() %} +{{ key }} {{ value }} +{% endfor %} diff --git a/templates/sasl_passwd.in.j2 b/templates/sasl_passwd.in.j2 deleted file mode 100644 index eb2cb968464c6e09a33297c6fafabe61d48914c5..0000000000000000000000000000000000000000 --- a/templates/sasl_passwd.in.j2 +++ /dev/null @@ -1,5 +0,0 @@ -# {{ ansible_managed }} - -{% for item in postfix__smtp_sasl_password_map %} -{{ item.lookup }} {{ item.credentials }} -{% endfor %} diff --git a/templates/transport.in.j2 b/templates/transport.in.j2 deleted file mode 100644 index 715d8a2fcaa0aaa01b7464bf195e36c9c345baa7..0000000000000000000000000000000000000000 --- a/templates/transport.in.j2 +++ /dev/null @@ -1,5 +0,0 @@ -# {{ ansible_managed }} - -{% for item in postfix__transport_map %} -{{ item.pattern }} {{ item.result }} -{% endfor %}