Browse Source

Fix for mysql import for virtualdomains

Tejinder Jheeta 11 years ago
parent
commit
b411e696d3
2 changed files with 19 additions and 11 deletions
  1. 7
    2
      roles/mailserver/tasks/postfix.yml
  2. 12
    9
      roles/mailserver/templates/mailserver.sql.j2

+ 7
- 2
roles/mailserver/tasks/postfix.yml View File

15
 - name: Create database for mail server
15
 - name: Create database for mail server
16
   mysql_db: name={{ mail_mysql_database }} state=present
16
   mysql_db: name={{ mail_mysql_database }} state=present
17
 
17
 
18
-  # i don't know why this import is failing but it is, so did this manually
19
-  # mysql_db: name={{ mail_mysql_database }} state=import target=templates/mailserver.sql.j2
18
+- name: copy over mailserver sql
19
+  template: src=mailserver.sql.j2 dest=/etc/postfix/import.sql owner=root group=root mode=0600
20
+  tags: import_mysql_postfix
21
+
22
+- name: import mysql postfix
23
+  mysql_db: name={{ mail_mysql_database }} state=import target=/etc/postfix/import.sql
24
+  tags: import_mysql_postfix
20
 
25
 
21
 - name: Copy Postfix config files into place
26
 - name: Copy Postfix config files into place
22
   template: src=etc_postfix_main.cf.j2 dest=/etc/postfix/main.cf owner=root group=root
27
   template: src=etc_postfix_main.cf.j2 dest=/etc/postfix/main.cf owner=root group=root

+ 12
- 9
roles/mailserver/templates/mailserver.sql.j2 View File

1
-CREATE TABLE `virtual_domains` (
1
+-- If tables are not dropped, have to truncate before insert or use "insert or replace" (not postgres compatible)
2
+
3
+DROP TABLE IF EXISTS `virtual_users`;
4
+DROP TABLE IF EXISTS `virtual_aliases`;
5
+DROP TABLE IF EXISTS `virtual_domains`;
6
+
7
+CREATE TABLE IF NOT EXISTS `virtual_domains` (
2
 	`id` int(11) NOT NULL auto_increment,
8
 	`id` int(11) NOT NULL auto_increment,
3
 	`name` varchar(50) NOT NULL,
9
 	`name` varchar(50) NOT NULL,
4
 	PRIMARY KEY (`id`)
10
 	PRIMARY KEY (`id`)
5
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
11
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6
 
12
 
7
-CREATE TABLE `virtual_users` (
13
+CREATE TABLE IF NOT EXISTS `virtual_users` (
8
 	`id` int(11) NOT NULL auto_increment,
14
 	`id` int(11) NOT NULL auto_increment,
9
 	`domain_id` int(11) NOT NULL,
15
 	`domain_id` int(11) NOT NULL,
10
 	`password` varchar(106) NOT NULL,
16
 	`password` varchar(106) NOT NULL,
14
 	FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
20
 	FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
15
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
 
22
 
17
-CREATE TABLE `virtual_aliases` (
23
+CREATE TABLE IF NOT EXISTS `virtual_aliases` (
18
 	`id` int(11) NOT NULL auto_increment,
24
 	`id` int(11) NOT NULL auto_increment,
19
 	`domain_id` int(11) NOT NULL,
25
 	`domain_id` int(11) NOT NULL,
20
 	`source` varchar(100) NOT NULL,
26
 	`source` varchar(100) NOT NULL,
24
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
30
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25
 
31
 
26
 {% for virtual_domain in mail_virtual_domains %}
32
 {% for virtual_domain in mail_virtual_domains %}
27
-	INSERT INTO `mailserver`.`virtual_domains` (`id`, `name`)
28
-	VALUES
29
-		('{{ virtual_domain.pk_id }}', '{{ virtual_domain.name }}');
33
+INSERT INTO `mailserver`.`virtual_domains` (`id`, `name`) VALUES ('{{ virtual_domain.pk_id }}', '{{ virtual_domain.name }}');
30
 {% endfor %}
34
 {% endfor %}
31
 
35
 
32
 {% for virtual_user in mail_virtual_users %}
36
 {% for virtual_user in mail_virtual_users %}
33
-	INSERT INTO `mailserver`.`virtual_users`  (`domain_id`, `password` , `email`)
34
-	VALUES
35
-  	('{{ virtual_domain.domain_pk_id }}', '{{ virtual_user.password_hash }}', '{{ virtual_user.address }}');
37
+INSERT INTO `mailserver`.`virtual_users`  (`domain_id`, `password` , `email`)
38
+	VALUES ('{{ virtual_user.domain_pk_id }}', '{{ virtual_user.password_hash }}', '{{ virtual_user.address }}');
36
 {% endfor %}
39
 {% endfor %}

Loading…
Cancel
Save