diff --git a/README.md b/README.md index 809a6fe..6f7c6f5 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ None * `postfix_default_database_type` [default: `hash`]: The default database type for use in `newaliases`, `postalias` and `postmap` commands * `postfix_aliases` [default: `[]`]: Aliases to ensure present in `/etc/aliases` + * `postfix_aliases_database_type` [default: `"{{ postfix_default_database_type }}"`]: The database type for aliases * `postfix_virtual_aliases` [default: `[]`]: Virtual aliases to ensure present in `/etc/postfix/virtual` * `postfix_sender_canonical_maps` [default: `[]`]: Sender address rewriting in `/etc/postfix/sender_canonical_maps` ([see](http://www.postfix.org/postconf.5.html#transport_maps)) * `postfix_sender_canonical_maps_database_type` [default: `"{{ postfix_default_database_type }}"`]: The database type for use in `postfix_sender_canonical_maps` @@ -177,6 +178,20 @@ Conditional relaying: result: "smtp:{{ ansible_lo['ipv4']['address'] }}:1025" ``` +Aliases with regexp table (forward all local mail to specified address): + +```yaml +--- +- hosts: all + roles: + - oefenweb.postfix + vars: + postfix_aliases_database_type: regexp + postfix_aliases: + - user: /.*/ + alias: you@yourdomain.org +``` + For AWS SES support: ```yaml diff --git a/defaults/main.yml b/defaults/main.yml index 0ae3c00..7ff626f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,6 +12,7 @@ postfix_mailname: "{{ ansible_fqdn }}" postfix_default_database_type: hash postfix_aliases: [] +postfix_aliases_database_type: "{{ postfix_default_database_type }}" postfix_virtual_aliases: [] postfix_sender_canonical_maps: [] postfix_sender_canonical_maps_database_type: "{{ postfix_default_database_type }}" diff --git a/handlers/main.yml b/handlers/main.yml index 1d6761e..ce2d541 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,7 +3,7 @@ - name: new aliases ansible.builtin.command: > newaliases - when: postfix_default_database_type != 'regexp' + when: postfix_aliases_database_type != 'regexp' changed_when: true - name: new virtual aliases diff --git a/tasks/main.yml b/tasks/main.yml index b7dd031..e50749c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -96,7 +96,7 @@ path: "{{ postfix_aliases_file }}.db" register: _aliasesdb changed_when: not _aliasesdb.stat.exists - when: postfix_default_database_type == 'hash' + when: postfix_aliases_database_type == 'hash' notify: - new aliases - restart postfix diff --git a/templates/etc/aliases.j2 b/templates/etc/aliases.j2 index 8dedf5e..3652d01 100644 --- a/templates/etc/aliases.j2 +++ b/templates/etc/aliases.j2 @@ -1,7 +1,13 @@ {{ ansible_managed | comment }} # See man 5 aliases for format +{% if postfix_aliases_database_type == 'regexp' %} +{% for alias in postfix_aliases %} +{{ alias.user }} {{ alias.alias }} +{% endfor %} +{% else %} postmaster: root {% for alias in postfix_aliases %} {{ alias.user }}: {{ alias.alias }} {% endfor %} +{% endif %} diff --git a/templates/etc/postfix/main.cf.j2 b/templates/etc/postfix/main.cf.j2 index 2be8118..8fbb392 100644 --- a/templates/etc/postfix/main.cf.j2 +++ b/templates/etc/postfix/main.cf.j2 @@ -37,8 +37,8 @@ smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache myhostname = {{ postfix_hostname }} default_database_type = {{ postfix_default_database_type }} -alias_maps = {{ postfix_default_database_type }}:{{ postfix_aliases_file }} -alias_database = {{ postfix_default_database_type }}:{{ postfix_aliases_file }} +alias_maps = {{ postfix_aliases_database_type }}:{{ postfix_aliases_file }} +alias_database = {{ postfix_aliases_database_type }}:{{ postfix_aliases_file }} {% if postfix_virtual_aliases %} virtual_alias_maps = {{ postfix_default_database_type }}:{{ postfix_virtual_aliases_file }} {% endif %}