add a host_vars template
[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 empty relay_clientcerts
64   when: postfix.relay_client_cert_whitelist is defined
65   register: relay_clientcerts
66   copy:
67     dest: /etc/postfix/relay_clientcerts
68     content: ""
69     force: no
70 - name: postmap relay_clientcerts
71   when: relay_clientcerts.changed
72   command: postmap /etc/postfix/relay_clientcerts
73   notify: postfix
74 - name: create transport_map
75   when: postfix.virtual_mailbox_domains is defined
76   register: transport_map
77   template:
78     dest: /etc/postfix/transport_map
79     src: templates/transport_map
80 - name: postmap transport_map
81   when: transport_map.changed
82   command: postmap /etc/postfix/transport_map
83   notify: postfix
84 # cronjobs
85 - name: delete old local-mail cronjob
86   file: path=/etc/cron.daily/local-mail state=absent
87 - name: install check-for-local-mail cronjob
88   copy:
89     dest: /etc/cron.daily/check-for-local-mail
90     src: files/check-for-local-mail
91     mode: u=rwx,g=rx,o=rx
92 - name: install mailman-check cronjob
93   when: postfix.mailman is defined and postfix.mailman
94   copy:
95     dest: /etc/cron.daily/mailman-check
96     src: files/mailman-check
97     mode: u=rwx,g=rx,o=rx
98 - name: remove mailman-check cronjob
99   when: not (postfix.mailman is defined and postfix.mailman)
100   file:
101     path: /etc/cron.daily/mailman-check
102     state: absent
103 # tools
104 - block:
105   - name: create newmail dir
106     file: path=/root/newmail state=directory
107   - name: install newmail script
108     copy:
109       dest: /root/newmail/newmail
110       src: files/newmail/newmail
111       mode: u=rwx,g=rx,o=rx
112   - name: install newmail templates
113     copy:
114       dest: /root/newmail/templates.py
115       src: files/newmail/templates.py
116   when: postfix.dovecot is defined