summaryrefslogtreecommitdiff
path: root/ansible/roles/mail-server/tasks/postfix.yml
blob: c691cd8cb41d435b2ade47ad94af3ef94c9e9707 (plain)
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
- name: install postfix
  apt:
    name: postfix

- name: install postgrey
  apt:
    name: postgrey

- name: install moreutils (for 
  apt:
    name: moreutils

- name: set /etc/mailname
  shell: |
    echo "{{ mail_hostname }}" > /etc/mailname

- name: install aliases map
  copy:
    src: aliases
    dest: /etc/aliases

- name: compile aliases map
  shell: newaliases

- name: install virtual map
  copy:
    src: virtual
    dest: /etc/postfix/virtual

- name: compile virtual map
  shell: postmap /etc/postfix/virtual

- name: configure postfix main.cf
  template:
    src: postfix.main.cf.j2
    dest: /etc/postfix/main.cf
  notify: restart postfix

- name: enable submission port in master.cf
  shell: |
    if ! grep '^submission'
    then
      (
        cat /etc/postfix/master.cf
        echo 'submission inet n - y - - smtpd'
      ) | sponge /etc/postfix/master.cf
    fi
  notify: restart postfix

- name: install whitelisted recipients for postgrey
  copy:
    src: whitelist_recipients.local
    dest: /etc/postgrey/whitelist_recipients.local
    owner: root
    group: root
    mode: 0644
  notify: restart postgrey

- name: install whitelisted sender domains for postgrey
  copy:
    src: whitelist_clients.local
    dest: /etc/postgrey/whitelist_clients.local
    owner: root
    group: root
    mode: 0644
  notify: restart postgrey

- name: install smarthost creds
  copy:
    content: "{{ smarthost }} {{ smarthost_user }}:{{ lookup('pipe', 'pass show ' + smarthost_pass_name) }}\n"
    dest: /etc/postfix/sasl_passwd
    owner: root
    group: root
    mode: 0600

- name: postmap smarthost creds
  shell: |
    postmap /etc/postfix/sasl_passwd
  notify: restart postfix