start dovecot config; generate postfix transport_map; support multiple sender IPs...
[ansible.git] / roles / email / tasks / postfix.yml
index bda22568fef15cd1af09e5cdbd40f776450db9ba..6644321dfa1b2cb4c793f4cf0e27e5c282797cdf 100644 (file)
@@ -1,7 +1,7 @@
 - name: install postfix
   apt: name=postfix,bsd-mailx state=latest
 - name: install postfix-mysql
 - name: install postfix
   apt: name=postfix,bsd-mailx state=latest
 - name: install postfix-mysql
-  when: postfix.vmail_mysql_password is defined
+  when: postfix.dovecot is defined
   apt: name=postfix-mysql state=latest
 - name: enable postfix
   service: name=postfix enabled=yes
   apt: name=postfix-mysql state=latest
 - name: enable postfix
   service: name=postfix enabled=yes
@@ -15,7 +15,7 @@
   - master.cf
   notify: postfix
 - name: install postfix mysql config
   - master.cf
   notify: postfix
 - name: install postfix mysql config
-  when: postfix.vmail_mysql_password is defined
+  when: postfix.dovecot is defined
   template:
     dest: /etc/postfix/{{ item }}
     src: templates/{{ item }}
   template:
     dest: /etc/postfix/{{ item }}
     src: templates/{{ item }}
   - mysql_vmail_senders.cf
   - mysql_vmail_users.cf
   notify: postfix
   - mysql_vmail_senders.cf
   - mysql_vmail_users.cf
   notify: postfix
-- name: create empty maps
-  when: postfix.virtual_mailbox_domains is defined
-  copy:
-    dest: /etc/postfix/{{ item }}
-    content: ""
-    force: no
-  loop:
-  - virtual_alias_map
-  - transport_map
 - name: give postfix user access to opendkim
   # we assume the user alredy exists (it is created above by installing postfix)
   when: postfix.opendkim is defined
 - name: give postfix user access to opendkim
   # we assume the user alredy exists (it is created above by installing postfix)
   when: postfix.opendkim is defined
     groups: opendkim
     append: yes
   notify: postfix
     groups: opendkim
     append: yes
   notify: postfix
+# maps
+- name: create empty virtual_alias_map
+  when: postfix.virtual_mailbox_domains is defined
+  register: virtual_alias_map
+  copy:
+    dest: /etc/postfix/virtual_alias_map
+    content: ""
+    force: no
+- name: postmap virtual_alias_map
+  when: virtual_alias_map.changed
+  command: postmap /etc/postfix/virtual_alias_map
+  notify: postfix
+- name: create transport_map
+  when: postfix.virtual_mailbox_domains is defined
+  register: transport_map
+  template:
+    dest: /etc/postfix/transport_map
+    src: templates/transport_map
+- name: postmap transport_map
+  when: transport_map.changed
+  command: postmap /etc/postfix/transport_map
+  notify: postfix
 # cronjobs
 - name: delete old local-mail cronjob
   file: path=/etc/cron.daily/local-mail state=absent
 # cronjobs
 - name: delete old local-mail cronjob
   file: path=/etc/cron.daily/local-mail state=absent
@@ -75,4 +88,4 @@
     copy:
       dest: /root/newmail/templates.py
       src: files/newmail/templates.py
     copy:
       dest: /root/newmail/templates.py
       src: files/newmail/templates.py
-  when: postfix.vmail_mysql_password is defined
+  when: postfix.dovecot is defined