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

- name: install moreutils (for sponge)
  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' /etc/postfix/master.cf
    then
      (
        cat /etc/postfix/master.cf
        echo 'submission inet n - y - - smtpd'
      ) | sponge /etc/postfix/master.cf
    fi
  notify: restart postfix

- 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