aboutsummaryrefslogtreecommitdiff
path: root/roles/icinga2/tasks/postfix.yml
blob: 044a93808d384736cb421d39f0cdb3e060d6e483 (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
---
- name: Install postfix relay creds
  copy:
    content: '{{ icinga.mail.smtp_host }} {{ icinga.mail.smtp_user }}:{{ icinga.mail.smtp_psw }}'
    dest: /etc/postfix/relay-credentials
    mode: '0600'
  become: yes
  register: relay_creds
  notify: Restart postfix

- name: Create hash db
  shell: postmap /etc/postfix/relay-credentials
  become: yes
  when: relay_creds.changed

- name: Install postfix relay creds
  copy:
    content: '{{ icinga.mail.from }} [{{ icinga.mail.smtp_host }}]:{{ icinga.mail.smtp_port }}'
    dest: /etc/postfix/bysender
  become: yes
  register: bysender
  notify: Restart postfix

- name: Create hash db
  shell: postmap /etc/postfix/bysender
  become: yes
  when: bysender.changed

- name: postfix config
  lineinfile:
    path: /etc/postfix/main.cf
    regexp: '{{ item.reg }}'
    line: '{{ item.line }}'
  loop:
    - reg: '^sender_dependent_relayhost_maps\w*=.*$'
      line: 'sender_dependent_relayhost_maps = hash:/etc/postfix/bysender'
    - reg: '^smtp_sasl_auth_enable\w*=.*$'
      line: 'smtp_sasl_auth_enable = yes'
    - reg: '^smtp_tls_security_level\w*=.*$'
      line: 'smtp_tls_security_level = encrypt'
    - reg: '^smtp_sasl_password_maps\w*=.*$'
      line: 'smtp_sasl_password_maps = hash:/etc/postfix/relay-credentials'
    - reg: '^smtp_use_tls\w*=.*$'
      line: 'smtp_use_tls = yes'
    - reg: '^smtp_sasl_security_options\w*=.*$'
      line: 'smtp_sasl_security_options = noanonymous'
  become: yes
  notify: Restart postfix