blob: e276267230cbba94d3417a6bd64e613c0e385dff [file] [log] [blame]
Andres Montalban8bd8bab2016-09-22 16:44:16 -03001{%- from "mysql/map.jinja" import server, mysql_connection_args with context %}
Jakub Pavlikf4396652016-07-11 15:06:33 +02002
Jakub Pavlikf4396652016-07-11 15:06:33 +02003{%- if server.enabled %}
4
5include:
6- mysql.common
7
8{%- if server.ssl.enabled %}
9
10/etc/mysql/server-cert.pem:
11 file.managed:
12 {%- if server.ssl.cert is defined %}
13 - contents_pillar: mysql:server:ssl:cert
14 {%- else %}
15 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.certificate }}.cert.pem
16 {%- endif %}
Dzmitry Stremkouski21e90302018-10-22 14:18:18 +020017 - mode: 644
Jakub Pavlikf4396652016-07-11 15:06:33 +020018 - require:
19 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020020 - watch_in:
21 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020022
23/etc/mysql/server-key.pem:
24 file.managed:
Martin Polreich6ca7c3f2017-08-30 15:07:57 +020025 {%- if server.ssl.key is defined %}
Jakub Pavlikf4396652016-07-11 15:06:33 +020026 - contents_pillar: mysql:server:ssl:key
27 {%- else %}
28 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.certificate }}.key.pem
29 {%- endif %}
Dzmitry Stremkouski21e90302018-10-22 14:18:18 +020030 - user: mysql
31 - mode: 400
Jakub Pavlikf4396652016-07-11 15:06:33 +020032 - require:
33 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020034 - watch_in:
35 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020036
37{%- if server.replication.role in ['slave', 'both'] %}
38
39/etc/mysql/client-cert.pem:
40 file.managed:
41 {%- if server.ssl.client_cert is defined %}
42 - contents_pillar: mysql:server:ssl:client_cert
43 {%- else %}
44 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.client_certificate }}.cert.pem
45 {%- endif %}
Dzmitry Stremkouski21e90302018-10-22 14:18:18 +020046 - mode: 644
Jakub Pavlikf4396652016-07-11 15:06:33 +020047 - require:
48 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020049 - watch_in:
50 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020051
52/etc/mysql/client-key.pem:
53 file.managed:
54 {%- if server.ssl.client_key is defined %}
55 - contents_pillar: mysql:server:ssl:client_key
56 {%- else %}
57 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.client_certificate }}.key.pem
58 {%- endif %}
Dzmitry Stremkouski21e90302018-10-22 14:18:18 +020059 - user: mysql
60 - mode: 400
Jakub Pavlikf4396652016-07-11 15:06:33 +020061 - require:
62 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020063 - watch_in:
64 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020065
66{%- endif %}
67
68/etc/mysql/cacert.pem:
69 file.managed:
70 {%- if server.ssl.cacert is defined %}
71 - contents_pillar: mysql:server:ssl:cacert
72 {%- else %}
73 - source: salt://pki/{{ server.ssl.authority }}/{{ server.ssl.authority }}-chain.cert.pem
74 {%- endif %}
Dzmitry Stremkouski21e90302018-10-22 14:18:18 +020075 - mode: 644
Jakub Pavlikf4396652016-07-11 15:06:33 +020076 - require:
77 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020078 - watch_in:
79 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020080
81{%- endif %}
82
83
84{%- if server.replication.role in ['master', 'both'] %}
85
86{{ server.replication.user }}:
87 mysql_user.present:
88 - host: '%'
89 - password: {{ server.replication.password }}
Andres Montalban8bd8bab2016-09-22 16:44:16 -030090 - connection_user: {{ mysql_connection_args.user }}
91 - connection_pass: {{ mysql_connection_args.password }}
92 - connection_charset: {{ mysql_connection_args.charset }}
Martin Polreich6ca7c3f2017-08-30 15:07:57 +020093 - watch:
Filip Pytloun05784e02016-08-25 12:24:14 +020094 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020095
96{{ server.replication.user }}_replication_grants:
97 mysql_grants.present:
98 - grant: replication slave
99 - database: '*.*'
100 - user: {{ server.replication.user }}
101 - host: '%'
Andres Montalban8bd8bab2016-09-22 16:44:16 -0300102 - connection_user: {{ mysql_connection_args.user }}
103 - connection_pass: {{ mysql_connection_args.password }}
104 - connection_charset: {{ mysql_connection_args.charset }}
Martin Polreich6ca7c3f2017-08-30 15:07:57 +0200105 - watch:
Filip Pytloun05784e02016-08-25 12:24:14 +0200106 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +0200107
108{%- endif %}
109
110{%- if server.replication.role in ['slave', 'both'] %}
111
112{%- if not salt['mysql.get_slave_status'] is defined %}
113
114{%- include "mysql/server/_connect_replication_slave.sls" %}
115
116{%- elif salt['mysql.get_slave_status']() == [] %}
117
118{%- include "mysql/server/_connect_replication_slave.sls" %}
119
120{%- else %}
121
122{%- if salt['mysql.get_slave_status']().get('Slave_SQL_Running', 'No') == 'Yes' and salt['mysql.get_slave_status']().get('Slave_IO_Running', 'No') == 'Yes' %}
123
124{%- else %}
125
126{%- include "mysql/server/_connect_replication_slave.sls" %}
127
128{%- endif %}
129
130{%- endif %}
131
132{%- endif %}
133
Filip Pytloun05784e02016-08-25 12:24:14 +0200134{%- endif %}