1
0
Fork 0
mirror of https://github.com/DO1JLR/ansible_playbook_servers.git synced 2024-09-14 19:53:56 +02:00

continue with sql stuff

This commit is contained in:
L3D 2021-01-03 01:01:18 +01:00
parent 458a88fca0
commit 5f12c582a8
Signed by: l3d
GPG key ID: CD08445BFF4313D1
6 changed files with 97 additions and 0 deletions

View file

@ -42,3 +42,6 @@ firewall_allowed_tcp_ports:
# mysql # mysql
mysql_bind_address: "{{ _mysql_bind_address }}" mysql_bind_address: "{{ _mysql_bind_address }}"
mysql_root_password: "{{ _mysql_root_password }}" mysql_root_password: "{{ _mysql_root_password }}"
# mailserver
mailserver_domain: "{{ inventory_hostname }}"

View file

@ -3,3 +3,5 @@ set_additional_nameserver: true
additional_v4nameserver: '46.182.19.48' additional_v4nameserver: '46.182.19.48'
additional_v6nameserver: '2a02:2970:1002::18' additional_v6nameserver: '2a02:2970:1002::18'
additional_dns_maildomains: "{{ ansible_fqdn }}" additional_dns_maildomains: "{{ ansible_fqdn }}"
mailserver_domain: "{{ ansible_fqdn }}"

View file

@ -0,0 +1,45 @@
CREATE DATABASE IF NOT EXISTS vmail CHARACTER SET 'utf8';
USE vmail;
CREATE TABLE `domains` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`domain` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`domain`)
);
CREATE TABLE `accounts` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL,
`domain` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`quota` int unsigned DEFAULT '0',
`enabled` boolean DEFAULT '0',
`sendonly` boolean DEFAULT '0',
PRIMARY KEY (id),
UNIQUE KEY (`username`, `domain`),
FOREIGN KEY (`domain`) REFERENCES `domains` (`domain`)
);
CREATE TABLE `aliases` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`source_username` varchar(64) NOT NULL,
`source_domain` varchar(255) NOT NULL,
`destination_username` varchar(64) NOT NULL,
`destination_domain` varchar(255) NOT NULL,
`enabled` boolean DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY (`source_username`, `source_domain`, `destination_username`, `destination_domain`),
FOREIGN KEY (`source_domain`) REFERENCES `domains` (`domain`)
);
CREATE TABLE `tlspolicies` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`domain` varchar(255) NOT NULL,
`policy` enum('none', 'may', 'encrypt', 'dane', 'dane-only', 'fingerprint', 'verify', 'secure') NOT NULL,
`params` varchar(255),
PRIMARY KEY (`id`),
UNIQUE KEY (`domain`)
);

View file

@ -27,3 +27,7 @@
mode: 0644 mode: 0644
owner: root owner: root
group: root group: root
- name: configure mariadb
include_tasks: mariadb.yml

View file

@ -0,0 +1,39 @@
---
- name: create database schema store dir
become: true
file:
path: /root/.mariadb_schema
state: directory
mode: '0755'
owner: root
group: root
- name: Copy database schema
become: true
copy:
src: files/schema.sql
dest: /root/.mariadb_schema/schema.sql
register: mysqlschema
- name: Copy mail config
become: true
template:
src: templates/mysqlconfig.sql.j2
dest: /root/.mariadb_schema/config.sql
register: mysqlconfig
- name: Import database schema
become: true
mssql_db:
name: vmail
state: import
target: '/root/.mariadb_schema/schema.sql'
when: mysqlschema.changed
- name: Import database schema
become: true
mssql_db:
name: vmail
state: import
target: '/root/.mariadb_schema/config.sql'
when: mysqlconfig.changed

View file

@ -0,0 +1,4 @@
use vmail;
insert into domains (domain) values ('{{ mailserver_domain }}');
insert into accounts (username, domain, password, quota, enabled, sendonly) values ('{{ mail_user }}', '{{ domain }}', '{{ mail_user_pass_hash }}', 2048, true, false);
insert into aliases (source_username, source_domain, destination_username, destination_domain, enabled) values ('alias', '{{ domain }}', '{{ mail_user }}', '{{ domain }}', true);