Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to set alias database type to regexp #135

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
# handlers file
---
- name: new aliases

Check warning on line 3 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
newaliases
when: postfix_default_database_type != 'regexp'
when: postfix_aliases_database_type != 'regexp'
changed_when: true

- name: new virtual aliases

Check warning on line 9 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_default_database_type }}:{{ postfix_virtual_aliases_file }}
when: postfix_default_database_type != 'regexp'
changed_when: true

- name: postmap sasl_passwd

Check warning on line 15 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_default_database_type }}:{{ postfix_sasl_passwd_file }}
when: postfix_default_database_type != 'regexp'
changed_when: true

- name: postmap sender_canonical_maps

Check warning on line 21 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_sender_canonical_maps_database_type }}:{{ postfix_sender_canonical_maps_file }}
when: postfix_sender_canonical_maps_database_type != 'regexp'
changed_when: true

- name: postmap recipient_canonical_maps

Check warning on line 27 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_recipient_canonical_maps_database_type }}:{{ postfix_recipient_canonical_maps_file }}
when: postfix_recipient_canonical_maps_database_type != 'regexp'
changed_when: true

- name: postmap transport_maps

Check warning on line 33 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_transport_maps_database_type }}:{{ postfix_transport_maps_file }}
when: postfix_transport_maps_database_type != 'regexp'
changed_when: true

- name: postmap sender_dependent_relayhost_maps

Check warning on line 39 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_default_database_type }}:{{ postfix_sender_dependent_relayhost_maps_file }}
when: postfix_default_database_type != 'regexp'
changed_when: true

- name: postmap generic

Check warning on line 45 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
postmap {{ postfix_smtp_generic_maps_database_type }}:{{ postfix_smtp_generic_maps_file }}
when: postfix_smtp_generic_maps_database_type != 'regexp'
changed_when: true

- name: remove pid

Check warning on line 51 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.file:
path: "~postfix/pid/master.pid"
state: absent
listen: restart postfix
when: is_docker_guest

- name: restart service

Check warning on line 58 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.service:
name: postfix
state: restarted
Expand Down
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions templates/etc/aliases.j2
Original file line number Diff line number Diff line change
@@ -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 %}
4 changes: 2 additions & 2 deletions templates/etc/postfix/main.cf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
Loading