summaryrefslogtreecommitdiffstats
path: root/roles/IMAP/tasks/imap.yml
blob: 75b250d84fecd4b267b908082c653f984007a956 (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
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
- name: Install Dovecot
  apt: pkg={{ item }}
  with_items:
    - dovecot-core
    - dovecot-ldap
    - dovecot-imapd
    - dovecot-lmtpd
    - dovecot-antispam
    - dovecot-managesieved
    - dovecot-sieve

- name: Create a user 'vmail'
  user: name=vmail system=yes
        createhome=no
        home=/home/mail
        shell=/usr/sbin/nologin
        password=!
        state=present

- name: Copy dovecot auth proxy
  copy: src=usr/local/bin/dovecot-auth-proxy.pl
        dest=/usr/local/bin/dovecot-auth-proxy.pl
        owner=root group=staff
        mode=0755

- name: Copy dovecot auth proxy systemd unit files
  copy: src=etc/systemd/system/{{ item }}
        dest=/etc/systemd/system/{{ item }}
        owner=root group=root
        mode=0644
  with_items:
    - dovecot-auth-proxy.service
    - dovecot-auth-proxy.socket
  notify:
    - systemctl daemon-reload

- meta: flush_handlers

- name: Enable dovecot auth proxy
  service: name=dovecot-auth-proxy.socket state=started enabled=yes

# The ownership and permissions ensure that dovecot won't try to
# deliver mails under an umounted mountpoint.
- name: Create a home directory for user 'vmail'
  file: path=/home/mail
        state=directory
        owner=root group=root
        mode=0755

- name: Create /home/mail/{virtual,attachments,spamspool}
  file: path=/home/mail/{{ item }}
        state=directory
        owner=vmail group=vmail
        mode=0700
  with_items:
    - virtual
    - attachments
    - spamspool

- name: Create a cronjob for purging and SIS deduplication
  copy: src=etc/cron.d/doveadm
        dest=/etc/cron.d/doveadm
        owner=root group=root
        mode=0644

- name: Create virtual mailbox directories
  file: path=/etc/dovecot/virtual/{{ item }}
        state=directory
        owner=root group=root
        mode=0755
  with_items:
    - all
    - flagged
    - recent
    - unseen

- name: Create virtual mailboxes
  copy: src=etc/dovecot/virtual/{{ item }}/dovecot-virtual
        dest=/etc/dovecot/virtual/{{ item }}/dovecot-virtual
        owner=root group=root
        mode=0644
  with_items:
    - all
    - flagged
    - recent
    - unseen

- name: Create directory /etc/dovecot/ssl
  file: path=/etc/dovecot/ssl
        state=directory
        owner=root group=root
        mode=0755


- name: Fetch Dovecot's X.509 certificate
  # Ensure we don't fetch private data
  become: False
  fetch_cmd: cmd="openssl x509 -noout -pubkey"
             stdin=/etc/dovecot/ssl/imap.fripost.org.pem
             dest=certs/public/imap.fripost.org.pub
  tags:
    - genkey

- name: Configure Dovecot
  copy: src=etc/dovecot/{{ item }}
        dest=/etc/dovecot/{{ item }}
        owner=root group=root
        mode=0644
  register: r1
  with_items:
    - conf.d/10-auth.conf
    - conf.d/10-logging.conf
    - conf.d/10-mail.conf
    - conf.d/10-ssl.conf
    - conf.d/15-mailboxes.conf
    # LDA is also used by LMTP
    - conf.d/15-lda.conf
    - conf.d/20-imap.conf
    - conf.d/20-lmtp.conf
    - conf.d/90-plugin.conf
    - conf.d/90-sieve.conf
    - conf.d/auth-ldap.conf.ext
    - dovecot-ldap.conf.ext
    - dovecot-ldap-userdb.conf.ext
  notify:
    - Restart Dovecot

- name: Configure Dovecot (2)
  template: src=etc/dovecot/{{ item }}.j2
            dest=/etc/dovecot/{{ item }}
            owner=root group=root
            mode=0644
  register: r2
  with_items:
    - conf.d/10-master.conf
  notify:
    - Restart Dovecot

- name: Tell Dovecot we have a remote IMAP proxy
  lineinfile: dest=/etc/dovecot/dovecot.conf
              regexp='^(\s*#)?\s*login_trusted_networks\s*='
              line="login_trusted_networks = {{ ipsec_subnet }}"
              state=present
              create=yes
              owner=root group=root
              mode=0644
  register: r3
  when: "groups.all | length > 1"
  notify:
    - Restart Dovecot

- name: Start Dovecot
  service: name=dovecot state=started
  when: not (r1.changed or r2.changed or r3.changed)

- meta: flush_handlers


- name: Install 'dovecot_stats_' Munin wildcard plugin
  file: src=/usr/local/share/munin/plugins/dovecot_stats_
        dest=/etc/munin/plugins/dovecot_stats_fripost.org
        owner=root group=root
        state=link force=yes
  tags:
    - munin
    - munin-node
  notify:
    - Restart munin-node

- name: Install 'dovecot_logins' and 'dovecot_who' Munin plugin
  file: src=/usr/local/share/munin/plugins/{{ item }}
        dest=/etc/munin/plugins/{{ item }}
        owner=root group=root
        state=link force=yes
  with_items:
    - dovecot_logins
    - dovecot_who
  tags:
    - munin
    - munin-node
  notify:
    - Restart munin-node