-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_server_setup.yml
97 lines (84 loc) · 2.39 KB
/
mail_server_setup.yml
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
---
- name: Ensure that we have mail server packages installed
apt: "name={{ item }} state=present"
loop:
- postfix
- postfix-pcre
- dovecot-imapd
- dovecot-pop3d
- dovecot-lmtpd
- dovecot-sieve
- opendkim
- opendkim-tools
- spamass-milter
- name: Ensure that mail system servers are running and start at boot
service: "name={{ item }} state=started enabled=yes"
loop:
- postfix
- dovecot
- spamassassin
- spamass-milter
- name: Combine all mail domains
set_fact:
all_mail_domains: "{{ mail_domains.keys() | list + [server_hostname] }}"
- name: Ensure that mailname is set to the hostname
template:
src: templates/etc_mailname.j2
dest: /etc/mailname
- name: Configure postfix
include_tasks: configure_postfix.yml
tags:
- postfix
- block:
- name: Configure dovecot
include_tasks: configure_dovecot.yml
tags: dovecot
- name: Configure spamassasin
include_tasks: configure_spamassassin.yml
tags:
- spamassassin
- name: Configure DKIM
include_tasks: configure_dkim.yml
tags:
- dkim
- name: Redirect mail meant for root to admin user
lineinfile:
dest: "/etc/aliases"
regexp: "^root:"
line: "root: admin"
state: present
notify: update aliases db
- name: Redirect mail sent to local postmaster user to admin user
lineinfile:
dest: "/etc/aliases"
regexp: "^postmaster:"
line: "postmaster: admin"
state: present
notify: update aliases db
- name: Redirect mail sent to postmaster for all domains to local postmaster user
lineinfile:
dest: "/etc/postfix/virtual"
create: true
regexp: '^postmaster@{{ item }}\s'
line: "postmaster@{{ item }} postmaster"
state: present
notify: update virtual alias maps db
with_items: "{{ all_mail_domains }}"
- name: Redirect mail sent to dmarc-reports for all domains to local postfix user
lineinfile:
dest: "/etc/postfix/virtual"
create: true
regexp: '^dmarc-reports@{{ item }}\s'
line: "dmarc-reports@{{ item }} postmaster"
state: present
notify: update virtual alias maps db
with_items: "{{ all_mail_domains }}"
- name: Ensure we have a directory for txt records
file:
path: ~/dns_txt_records
state: directory
- name: Generate TXT records for DKIM, DMARC, SPF for hosted domains
include_tasks: generate_txt_records.yml
loop: "{{ mail_domains.keys() | list }}"
loop_control:
loop_var: domain