aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/postfix/tasks/main.yml
blob: 5281fff018c1ea54dccc542ad802fb029c77e62f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---
- name: Install postfix & tools
  package:
    name:
      # Postfix & routing plugins
      - postfix
      - postfix-ldap
      # RegExp based lookup tables
      - postfix-pcre
      # Relay routing utilities
      - postsrsd
      # Security and anti-spam tools
      - postfix-policyd-spf-python
      # Mail scripting utilities
      - mblaze
      - at
    state: present
  tags:
    - role::postfix

- name: Configure /etc/mailname to mail hostname
  copy:
    content: "{{ postfix_mailname }}\n"
    dest: /etc/mailname
    owner: root
    group: root
    mode: "0644"
  tags:
    - role::postfix
  notify:
    - Reload postfix

- name: Template Postfix main.cf config file
  template:
    src: main.cf.j2
    dest: /etc/postfix/main.cf
    owner: root
    group: root
    mode: "0644"
  tags:
    - role::postfix
  notify:
    - Reload postfix

- name: Template Postfix LDAP config files
  template:
    src: "{{ item.template }}"
    dest: "/etc/postfix/{{ item.filename }}"
    owner: root
    group: root
    mode: "0644"
  loop:
    - template: ldap/ldap-registeredaddress.cf.j2
      filename: ldap-registeredaddress.cf
    - template: ldap/ldap-uid.cf.j2
      filename: ldap-uid.cf
    - template: ldap/ldap-relay-recipients.cf.j2
      filename: ldap-relay-recipients.cf
    - template: ldap/ldap-group-aliases.cf.j2
      filename: ldap-group-aliases.cf
    - template: ldap/ldap-service-mail.cf.j2
      filename: ldap-service-mail.cf
  tags:
    - role::postfix
  notify:
    - Reload postfix

- name: Copy virtual address table
  template:
    src: virtual.j2
    dest: /etc/postfix/virtual
    owner: root
    group: root
    mode: "0644"
  tags:
    - role::postfix
  notify:
    - Regenerate virtual table
    - Reload postfix

- name: Copy policyd-spf config
  copy:
    src: policyd-spf.conf
    dest: /etc/postfix-policyd-spf-python/policyd-spf.conf
    mode: "0644"
    group: root
    owner: root
  tags:
    - role::postfix
  notify:
    - Restart postfix

- name: Template sender canonical map lookup
  template:
    src: sender-canonical-maps.j2
    dest: /etc/postfix/sender-canonical-maps
    mode: "0644"
    group: root
    owner: root
  tags:
    - role::postfix

- name: Create Postfix service directory
  file:
    path: "/etc/postfix/service-scripts"
    owner: root
    group: servicemailer
    mode: "0755"
    state: directory
  tags:
    - role::postfix

- name: Template Postfix automated scripts
  template:
    src: "{{ item }}"
    dest: "/etc/postfix/service-scripts/{{ item | basename | splitext | first }}"
    mode: "0754"
    owner: root
    group: servicemailer
  loop_control:
    label: "{{ item | basename | splitext | first }}"
  with_fileglob: "../templates/services/*"
  tags:
    - role::postfix
    - role::postfix::service-scripts

- name: Template Postfix mail transport map
  template:
    src: transport.j2
    dest: /etc/postfix/transport
    mode: "0644"
    owner: root
    group: root
  tags:
    - role::postfix
  notify: Regenerate transport table

- name: Copy Postfix sender access list
  copy:
    src: sender_access
    dest: /etc/postfix/sender_access
    mode: "0644"
    owner: root
    group: root
  tags:
    - role::postfix
  notify: Regenerate sender access table

- name: Template Postfix submission header checks
  template:
    src: header-checks-submission.j2
    dest: /etc/postfix/header-checks-submission
    mode: "0o444"
    owner: root
    group: root
  notify:
    - Reload postfix
  tags:
    - role::postfix

- name: Update PostSRSD rewriting config
  lineinfile:
    path: /etc/default/postsrsd
    regexp: "^#?{{ item['key'] }}="
    line: '{{ item["key"] }}="{{ item["value"] }}"'
    mode: "0444"
    owner: root
    group: root
  loop:
    - key: SRS_EXCLUDE_DOMAINS
      value: "{{ postfix_destination_domains | join(',') }}"
  tags:
    - role::postfix
  notify:
    - Restart postsrsd

- name: Pass inbound mail through spamassassin content filter
  lineinfile:
    path: /etc/postfix/master.cf
    insertafter: "smtp      inet  n       -       y       -       -       smtpd"
    line: " -o content_filter=spamassassin"
  tags:
    - role::postfix
  notify:
    - Restart postfix

- name: Add custom services to master.cf
  blockinfile:
    path: /etc/postfix/master.cf
    append_newline: true
    prepend_newline: true
    block: |
      policyd-spf  unix  -       n       n       -       0       spawn
        user=policyd-spf argv=/usr/bin/policyd-spf

      submission     inet     n    -    y    -    -    smtpd
        -o syslog_name=postfix/submission
        -o smtpd_tls_security_level=encrypt
        -o smtpd_tls_wrappermode=no
        -o smtpd_sasl_auth_enable=yes
        -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
        -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
        -o smtpd_sasl_type=dovecot
        -o smtpd_sasl_path=private/auth
        -o cleanup_service_name=authcleanup

      smtps     inet  n       -       y       -       -       smtpd
        -o syslog_name=postfix/smtps
        -o smtpd_tls_wrappermode=yes
        -o smtpd_sasl_auth_enable=yes
        -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
        -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
        -o smtpd_sasl_type=dovecot
        -o smtpd_sasl_path=private/auth

      cleanup-srs     unix n - - - 0 cleanup
        -o syslog_name=postfix/cleanup/optional-srs
        -o sender_canonical_maps=pcre:/etc/postfix/sender-canonical-maps,tcp:127.0.0.1:10001
        -o sender_canonical_classes=envelope_sender

      127.0.0.1:10027 inet n - y - - smtpd
        -o syslog_name=postfix/cleanup/optional-srs
        -o smtpd_milters=
        -o cleanup_service_name=cleanup-srs
        -o smtpd_tls_security_level=none
        -o content_filter=smtp:
        -o smtpd_recipient_restrictions=permit_mynetworks,reject

      # spamassassin filtering
      spamassassin unix -     n       n       -       -       pipe
        user=debian-spamd argv=/usr/bin/spamc -f -e
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}

      # authenticated submission cleanup
      authcleanup unix  n       -       y       -       0       cleanup
        -o header_checks=pcre:/etc/postfix/header-checks-submission
        -o nested_header_checks=

      # Service Mail pipes
      fortune-pipe unix  -       n       n       -       -       pipe
        flags=Fq user=servicemailer argv=/etc/postfix/service-scripts/fortune-reply.sh

      fredrick-pipe unix  -       n       n       -       -       pipe
        flags=Fq user=servicemailer argv=/etc/postfix/service-scripts/fredrick-reply.sh
  tags:
    - role::postfix
    - role::postfix::service-scripts
  notify:
    - Restart postfix