Просмотр исходного кода

Generate mail autoconfig for all domains and put them in well-known too

Thomas Buck 5 лет назад
Родитель
Сommit
f7094f17dd

+ 2
- 1
roles/mailserver/defaults/main.yml Просмотреть файл

@@ -10,7 +10,8 @@ mail_db_username: 'mailuser'
10 10
 mail_db_password: "{{ lookup('password', secret + '/' + 'mail_db_password length=32') }}"
11 11
 mail_db_database: 'mailserver'
12 12
 
13
-mail_server_hostname: "mail.{{ domain }}"
13
+mail_server_subdomain: "mail"
14
+mail_server_hostname: "{{ mail_server_subdomain }}.{{ domain }}"
14 15
 mail_server_autoconfig_hostname: "autoconfig.{{ domain }}"
15 16
 mail_header_privacy: 1
16 17
 

+ 11
- 11
roles/mailserver/tasks/autoconfig.yml Просмотреть файл

@@ -2,28 +2,28 @@
2 2
 #
3 3
 # Autoconfig XML file for email clients
4 4
 # https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration
5
-#
6
-
7
-- name: Create directory for mail autoconfiguration virtualhost
8
-  file:
9
-    state=directory
10
-    path=/var/www/autoconfig
11
-    owner=root
12
-    group=www-data
13 5
 
14
-- name: Create directory holding the autoconfig XML file
6
+- name: Create directories holding the autoconfig XML file
15 7
   file:
16 8
     state=directory
17
-    path=/var/www/autoconfig/mail
9
+    path={{ item }}
18 10
     owner=root
19 11
     group=www-data
12
+  with_items:
13
+    - "/var/www/autoconfig"
14
+    - "/var/www/autoconfig/mail"
15
+    - "/var/www/well-known/autoconfig"
16
+    - "/var/www/well-known/autoconfig/mail"
20 17
 
21 18
 - name: Create the autoconfig XML file
22 19
   template:
23 20
     src=var_www_autoconfig_mail_config-v1.1.j2
24
-    dest=/var/www/autoconfig/mail/config-v1.1.xml
21
+    dest={{ item }}
25 22
     owner=root
26 23
     group=www-data
24
+  with_items:
25
+    - "/var/www/autoconfig/mail/config-v1.1.xml"
26
+    - "/var/www/well-known/autoconfig/mail/config-v1.1.xml"
27 27
 
28 28
 - name: Configure the mail autoconfiguration virtualhost
29 29
   template:

+ 9
- 7
roles/mailserver/templates/var_www_autoconfig_mail_config-v1.1.j2 Просмотреть файл

@@ -1,29 +1,31 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <clientConfig version="1.1">
3
-    <emailProvider id="{{ domain }}">
4
-        <domain>{{ domain }}</domain>
5
-        <displayName>{{ domain }}</displayName>
6
-        <displayShortName>{{ domain }}</displayShortName>
3
+{% for vd in virtual_domains %}
4
+    <emailProvider id="{{ vd.name }}">
5
+        <domain>{{ vd.name }}</domain>
6
+        <displayName>{{ vd.name }}</displayName>
7
+        <displayShortName>{{ vd.name }}</displayShortName>
7 8
         <incomingServer type="imap">
8
-            <hostname>{{ mail_server_hostname }}</hostname>
9
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
9 10
             <port>993</port>
10 11
             <socketType>SSL</socketType>
11 12
             <authentication>password-cleartext</authentication>
12 13
             <username>%EMAILADDRESS%</username>
13 14
         </incomingServer>
14 15
         <incomingServer type="pop3">
15
-            <hostname>{{ mail_server_hostname }}</hostname>
16
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
16 17
             <port>995</port>
17 18
             <socketType>SSL</socketType>
18 19
             <authentication>password-cleartext</authentication>
19 20
             <username>%EMAILADDRESS%</username>
20 21
         </incomingServer>
21 22
         <outgoingServer type="smtp">
22
-            <hostname>{{ mail_server_hostname }}</hostname>
23
+            <hostname>{{ mail_server_subdomain }}.{{ vd.name }}</hostname>
23 24
             <port>587</port>
24 25
             <socketType>STARTTLS</socketType>
25 26
             <authentication>password-cleartext</authentication>
26 27
             <username>%EMAILADDRESS%</username>
27 28
         </outgoingServer>
28 29
     </emailProvider>
30
+{% endfor %}
29 31
 </clientConfig>

Загрузка…
Отмена
Сохранить