blob: 4d724e2724e01bd0d861d28bce4337775c826a04 [file] [log] [blame]
Jakub Pavlikf4396652016-07-11 15:06:33 +02001{%- from "mysql/map.jinja" import server with context %}
2
3mysql_salt_config:
4 file.managed:
5 - name: /etc/salt/minion.d/mysql.conf
6 - template: jinja
7 - source: salt://mysql/files/salt-minion.conf
8 - mode: 600
9
10{%- if server.enabled %}
11
12include:
13- mysql.common
14
15{%- if server.ssl.enabled %}
16
17/etc/mysql/server-cert.pem:
18 file.managed:
19 {%- if server.ssl.cert is defined %}
20 - contents_pillar: mysql:server:ssl:cert
21 {%- else %}
22 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.certificate }}.cert.pem
23 {%- endif %}
24 - require:
25 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020026 - watch_in:
27 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020028
29/etc/mysql/server-key.pem:
30 file.managed:
31 {%- if server.ssl.cert is defined %}
32 - contents_pillar: mysql:server:ssl:key
33 {%- else %}
34 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.certificate }}.key.pem
35 {%- endif %}
36 - require:
37 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020038 - watch_in:
39 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020040
41{%- if server.replication.role in ['slave', 'both'] %}
42
43/etc/mysql/client-cert.pem:
44 file.managed:
45 {%- if server.ssl.client_cert is defined %}
46 - contents_pillar: mysql:server:ssl:client_cert
47 {%- else %}
48 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.client_certificate }}.cert.pem
49 {%- endif %}
50 - require:
51 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020052 - watch_in:
53 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020054
55/etc/mysql/client-key.pem:
56 file.managed:
57 {%- if server.ssl.client_key is defined %}
58 - contents_pillar: mysql:server:ssl:client_key
59 {%- else %}
60 - source: salt://pki/{{ server.ssl.authority }}/certs/{{ server.ssl.client_certificate }}.key.pem
61 {%- endif %}
62 - require:
63 - pkg: mysql_packages
Filip Pytloun05784e02016-08-25 12:24:14 +020064 - watch_in:
65 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020066
67{%- endif %}
68
69/etc/mysql/cacert.pem:
70 file.managed:
71 {%- if server.ssl.cacert is defined %}
72 - contents_pillar: mysql:server:ssl:cacert
73 {%- else %}
74 - source: salt://pki/{{ server.ssl.authority }}/{{ server.ssl.authority }}-chain.cert.pem
75 {%- endif %}
76 - 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 }}
Filip Pytloun05784e02016-08-25 12:24:14 +020090 - watch_in:
91 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +020092
93{{ server.replication.user }}_replication_grants:
94 mysql_grants.present:
95 - grant: replication slave
96 - database: '*.*'
97 - user: {{ server.replication.user }}
98 - host: '%'
Filip Pytloun05784e02016-08-25 12:24:14 +020099 - watch_in:
100 - service: mysql_service
Jakub Pavlikf4396652016-07-11 15:06:33 +0200101
102{%- endif %}
103
104{%- if server.replication.role in ['slave', 'both'] %}
105
106{%- if not salt['mysql.get_slave_status'] is defined %}
107
108{%- include "mysql/server/_connect_replication_slave.sls" %}
109
110{%- elif salt['mysql.get_slave_status']() == [] %}
111
112{%- include "mysql/server/_connect_replication_slave.sls" %}
113
114{%- else %}
115
116{%- if salt['mysql.get_slave_status']().get('Slave_SQL_Running', 'No') == 'Yes' and salt['mysql.get_slave_status']().get('Slave_IO_Running', 'No') == 'Yes' %}
117
118{%- else %}
119
120{%- include "mysql/server/_connect_replication_slave.sls" %}
121
122{%- endif %}
123
124{%- endif %}
125
126{%- endif %}
127
Filip Pytloun05784e02016-08-25 12:24:14 +0200128{%- endif %}