Skip to content

Commit f50394a

Browse files
authored
Merge pull request #150 from Oefenweb/pr-149
Add support for multiple relayhosts
2 parents 3611b87 + 36c789f commit f50394a

File tree

8 files changed

+34
-32
lines changed

8 files changed

+34
-32
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Check out the codebase
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v5
1919

2020
- name: Set up Python 3
21-
uses: actions/setup-python@v4
21+
uses: actions/setup-python@v6
2222
with:
23-
python-version: '3.x'
23+
python-version: '3 - 3.13'
2424

2525
- name: Install test dependencies
2626
run: |
@@ -44,30 +44,30 @@ jobs:
4444
fail-fast: false
4545
matrix:
4646
include:
47-
- distro: debian10
48-
ansible-version: '>=9, <10'
4947
- distro: debian11
5048
- distro: debian12
5149
- distro: ubuntu1804
5250
ansible-version: '>=9, <10'
5351
- distro: ubuntu2004
52+
ansible-version: '>=12, <13'
5453
- distro: ubuntu2204
5554
- distro: ubuntu2404
5655

5756
steps:
5857
- name: Check out the codebase
59-
uses: actions/checkout@v3
58+
uses: actions/checkout@v5
6059
with:
6160
path: "${{ github.repository }}"
6261

6362
- name: Set up Python 3
64-
uses: actions/setup-python@v4
63+
uses: actions/setup-python@v6
6564
with:
66-
python-version: '3.x'
65+
python-version: '3 - 3.13'
6766

6867
- name: Install test dependencies
6968
run: |
7069
pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker
70+
7171
- name: Run Molecule tests
7272
run: |
7373
molecule test

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Check out the codebase
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v5
1616

1717
- name: Publish to Galaxy
1818
uses: robertdebock/galaxy-action@1.2.0

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ None
4141
* `postfix_smtp_ipv4_bind` [optional]: Outbound network interfaces to use (IPv4) ([see](http://www.postfix.org/postconf.5.html#smtp_bind_address))
4242
* `postfix_smtp_ipv6_bind` [optional]: Outbound network interfaces to use (IPv6) ([see](http://www.postfix.org/postconf.5.html#smtp_bind_address6))
4343

44-
* `postfix_relayhost` [default: `''` (no relay host)]: Hostname to relay all email to
45-
* `postfix_relayhost_mxlookup` [default: `false` (not using mx lookup)]: Lookup for MX record instead of A record for relayhost
46-
* `postfix_relayhost_port` [default: 587]: Relay port (on `postfix_relayhost`, if set)
44+
* `postfix_relayhost` [default: `''` (no relay host)]: Hostname to relay all email to. **Deprecated**, use `postfix_relayhosts`.
45+
* `postfix_relayhosts` [default: `[]` (no relay host)]: List of hostnames to relay all email to (setting multiple hosts only works in **postfix 3.5 and later**)
46+
* `postfix_relayhost_mxlookup` [default: `false` (not using mx lookup)]: Lookup for MX record instead of A record for relayhosts
47+
* `postfix_relayhost_port` [default: `587`]: Relay port (on all hosts in `postfix_relayhosts`)
4748
* `postfix_relaytls` [default: `false`]: Use TLS when sending with a relay host
4849

4950
* `postfix_smtpd_client_restrictions` [optional]: List of client restrictions ([see](http://www.postfix.org/postconf.5.html#smtpd_client_restrictions))
@@ -149,7 +150,7 @@ Provide the relay host name if you want to enable relaying:
149150
postfix_aliases:
150151
- user: root
151152
alias: you@yourdomain.org
152-
postfix_relayhost: mail.yourdomain.org
153+
postfix_relayhosts: [mail.yourdomain.org]
153154
```
154155
155156
Provide the relay domain name and use MX records if you want to enable relaying to DNS MX records of a domain:
@@ -163,7 +164,7 @@ Provide the relay domain name and use MX records if you want to enable relaying
163164
postfix_aliases:
164165
- user: root
165166
alias: you@yourdomain.org
166-
postfix_relayhost: yourdomain.org
167+
postfix_relayhosts: [yourdomain.org]
167168
postfix_relayhost_mxlookup: true
168169
```
169170
@@ -214,7 +215,7 @@ For AWS SES support:
214215
postfix_aliases:
215216
- user: root
216217
alias: sesverified@yourdomain.org
217-
postfix_relayhost: email-smtp.us-east-1.amazonaws.com
218+
postfix_relayhost: [email-smtp.us-east-1.amazonaws.com]
218219
postfix_relaytls: true
219220
# AWS IAM SES credentials (not access key):
220221
postfix_sasl_user: AKIXXXXXXXXXXXXXXXXX
@@ -232,7 +233,7 @@ For MailHog support:
232233
postfix_aliases:
233234
- user: root
234235
alias: you@yourdomain.org
235-
postfix_relayhost: "{{ ansible_lo['ipv4']['address'] }}"
236+
postfix_relayhost: ["{{ ansible_lo['ipv4']['address'] }}"]
236237
postfix_relayhost_port: 1025
237238
postfix_sasl_auth_enable: false
238239
```
@@ -248,7 +249,7 @@ For Gmail support:
248249
postfix_aliases:
249250
- user: root
250251
alias: you@yourdomain.org
251-
postfix_relayhost: smtp.gmail.com
252+
postfix_relayhost: [smtp.gmail.com]
252253
postfix_relaytls: true
253254
postfix_smtp_tls_cafile: /etc/ssl/certs/ca-certificates.crt
254255
postfix_sasl_user: 'foo'

Vagrantfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ boxes = [
3232
:cpu => "50",
3333
:ram => "512"
3434
},
35-
{
36-
:name => "debian-10",
37-
:box => "bento/debian-10",
38-
:ip => '10.0.0.18',
39-
:cpu => "50",
40-
:ram => "256"
41-
},
4235
{
4336
:name => "debian-11",
4437
:box => "bento/debian-11",

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ postfix_generic: "{{ postfix_smtp_generic_maps }}"
2727
postfix_smtp_generic_maps: []
2828
postfix_smtp_generic_maps_database_type: "{{ postfix_default_database_type }}"
2929

30-
postfix_relayhost: ''
30+
postfix_relayhosts: []
3131
postfix_relayhost_mxlookup: false
3232
postfix_relayhost_port: 587
3333
postfix_relaytls: false

meta/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ galaxy_info:
1616
- noble
1717
- name: Debian
1818
versions:
19-
- buster
2019
- bullseye
2120
- bookworm
2221
galaxy_tags:

tasks/main.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# tasks file
22
---
33
- name: facts | set
4-
ansible.builtin.set_fact:
5-
is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}"
64
tags:
75
- configuration
86
- postfix
97
- postfix-facts
8+
block:
9+
- name: facts | set | is_docker_guest
10+
ansible.builtin.set_fact:
11+
is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}"
12+
13+
- name: facts | set | postfix_relayhosts
14+
ansible.builtin.set_fact:
15+
postfix_relayhosts: ["{{ postfix_relayhost }}"]
16+
when:
17+
- postfix_relayhosts | length == 0
18+
- postfix_relayhost is defined
1019

1120
- name: configure debconf
1221
ansible.builtin.debconf:
@@ -65,7 +74,7 @@
6574
group: root
6675
mode: '0600'
6776
when:
68-
- postfix_relayhost | length > 0
77+
- postfix_relayhosts | length > 0
6978
- postfix_sasl_auth_enable | bool
7079
no_log: "{{ not ansible_check_mode }}"
7180
notify:

templates/etc/postfix/main.cf.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ inet_protocols = {{ postfix_inet_protocols }}
100100
inet_protocols = {{ postfix_inet_protocols | join(', ') }}
101101
{% endif %}
102102

103-
{% if postfix_relayhost %}
103+
{% if postfix_relayhosts %}
104104
{% if postfix_relayhost_mxlookup %}
105-
relayhost = {{ postfix_relayhost }}:{{ postfix_relayhost_port }}
105+
relayhost = {% for host in postfix_relayhosts %}{{ host }}:{{ postfix_relayhost_port }}{{ ', ' if not loop.last else '' }}{% endfor %}
106106
{% else %}
107-
relayhost = [{{ postfix_relayhost }}]:{{ postfix_relayhost_port }}
107+
relayhost = {% for host in postfix_relayhosts %}[{{ host }}]:{{ postfix_relayhost_port }}{{ ', ' if not loop.last else '' }}{% endfor %}
108108
{% endif %}
109109
{% if postfix_sasl_auth_enable %}
110110
smtp_sasl_auth_enable = {{ postfix_sasl_auth_enable | bool | ternary('yes', 'no') }}

0 commit comments

Comments
 (0)