generate relay_clientcerts whitelist from host_vars
[ansible.git] / roles / email / tasks / postfix.yml
1 - name: install postfix
2   apt: name=postfix,bsd-mailx state=latest
3 - name: install postfix-mysql
4   when: postfix.dovecot is defined
5   apt: name=postfix-mysql state=latest
6 - name: enable postfix
7   service: name=postfix enabled=yes
8 - name: install mailman
9   when: postfix.mailman is defined and postfix.mailman
10   apt: name=mailman state=latest
11 # config
12 - name: install postfix config
13   template:
14     dest: /etc/postfix/{{ item }}
15     src: templates/{{ item }}
16   loop:
17   - main.cf
18   - master.cf
19   notify: postfix
20 - name: install postfix mysql config
21   when: postfix.dovecot is defined
22   template:
23     dest: /etc/postfix/{{ item }}
24     src: templates/{{ item }}
25     mode: u=rw,g=r,o=
26     group: postfix
27   loop:
28   - mysql_vmail_aliases.cf
29   - mysql_vmail_senders.cf
30   - mysql_vmail_users.cf
31   notify: postfix
32 - name: give postfix user access to opendkim
33   # we assume the user alredy exists (it is created above by installing postfix)
34   when: postfix.opendkim is defined
35   user:
36     name: postfix
37     groups: opendkim
38     append: yes
39   notify: postfix
40 # maps
41 - name: create empty virtual_alias_map
42   when: postfix.virtual_mailbox_domains is defined
43   register: virtual_alias_map
44   copy:
45     dest: /etc/postfix/virtual_alias_map
46     content: ""
47     force: no
48 - name: postmap virtual_alias_map
49   when: virtual_alias_map.changed
50   command: postmap /etc/postfix/virtual_alias_map
51   notify: postfix
52 - name: create empty sender_transport_map
53   when: postfix.smtp_outgoing is defined
54   register: sender_transport_map
55   copy:
56     dest: /etc/postfix/sender_transport_map
57     content: ""
58     force: no
59 - name: postmap sender_transport_map
60   when: sender_transport_map.changed
61   command: postmap /etc/postfix/sender_transport_map
62   notify: postfix
63 - name: create relay_clientcerts
64   when: postfix.relay_client_cert_whitelist is defined
65   register: relay_clientcerts
66   template:
67     dest: /etc/postfix/relay_clientcerts
68     src: templates/relay_clientcerts
69 - name: postmap relay_clientcerts
70   when: relay_clientcerts.changed
71   command: postmap /etc/postfix/relay_clientcerts
72   notify: postfix
73 - name: create transport_map
74   when: postfix.virtual_mailbox_domains is defined
75   register: transport_map
76   template:
77     dest: /etc/postfix/transport_map
78     src: templates/transport_map
79 - name: postmap transport_map
80   when: transport_map.changed
81   command: postmap /etc/postfix/transport_map
82   notify: postfix
83 # cronjobs
84 - name: delete old local-mail cronjob
85   file: path=/etc/cron.daily/local-mail state=absent
86 - name: install check-for-local-mail cronjob
87   copy:
88     dest: /etc/cron.daily/check-for-local-mail
89     src: files/check-for-local-mail
90     mode: u=rwx,g=rx,o=rx
91 - name: install mailman-check cronjob
92   when: postfix.mailman is defined and postfix.mailman
93   copy:
94     dest: /etc/cron.daily/mailman-check
95     src: files/mailman-check
96     mode: u=rwx,g=rx,o=rx
97 - name: remove mailman-check cronjob
98   when: not (postfix.mailman is defined and postfix.mailman)
99   file:
100     path: /etc/cron.daily/mailman-check
101     state: absent
102 # tools
103 - block:
104   - name: create newmail dir
105     file: path=/root/newmail state=directory
106   - name: install newmail script
107     copy:
108       dest: /root/newmail/newmail
109       src: files/newmail/newmail
110       mode: u=rwx,g=rx,o=rx
111   - name: install newmail templates
112     copy:
113       dest: /root/newmail/templates.py
114       src: files/newmail/templates.py
115   when: postfix.dovecot is defined