blob: 3990db5bf26b79c46006735b5ff8dab1031e42f5 [file] [log] [blame]
Filip Pytloun5b3c12e2015-10-06 16:28:32 +02001{%- from "mysql/map.jinja" import server with context %}
2
3{%- if server.admin is defined %}
4
5mariadb_debconf:
6 debconf.set:
7 - name: mariadb-server
8 - data:
9 'mysql-server/root_password': {'type':'string','value':'{{ server.admin.password }}'}
10 'mysql-server/root_password_again': {'type':'string','value':'{{ server.admin.password }}'}
Martin Polreich6ca7c3f2017-08-30 15:07:57 +020011 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020012 - pkg: mysql_packages
13
14{%- endif %}
15
16mysql_packages:
17 pkg.installed:
18 - names: {{ server.pkgs }}
19
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020020mysql_config:
21 file.managed:
22 - name: {{ server.config }}
23 - source: salt://mysql/conf/my.cnf.{{ grains.os_family }}
24 - mode: 644
25 - template: jinja
Filip Pytloun8980ef52016-05-24 17:11:50 +020026 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020027 - pkg: mysql_packages
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020028
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020029mysql_service:
30 service.running:
31 - name: {{ server.service }}
32 - enable: true
Filip Pytloun8980ef52016-05-24 17:11:50 +020033 - watch:
34 - file: mysql_config
Filip Pytloun8980ef52016-05-24 17:11:50 +020035
36{%- if grains.get('virtual_subtype', None) == "Docker" %}
37mysql_entrypoint:
38 file.managed:
39 - name: /entrypoint.sh
40 - template: jinja
41 - source: salt://mysql/files/entrypoint.sh
42 - mode: 755
43{%- endif %}
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020044
45mysql_config_dir:
46 file.directory:
47 - name: /etc/mysql/conf.d
48 - makedirs: true
49 - mode: 755
50
51mysql_dirs:
52 file.directory:
53 - names:
54 - /root/mysql/scripts
55 - /root/mysql/flags
56 - /root/mysql/data
57 - mode: 700
58 - user: root
59 - group: root
60 - makedirs: true
Filip Pytloun8980ef52016-05-24 17:11:50 +020061 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020062 - pkg: mysql_packages
63
64/root/mysql/flags:
65 file.directory:
66 - mode: 700
67 - user: root
68 - group: root
69 - makedirs: true
Filip Pytloun8980ef52016-05-24 17:11:50 +020070 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +020071 - pkg: mysql_packages
72
73
74{#
75# Backup part
76#}
77
78{#
79# Backup part - automysqlbackup
80#}
81
82{% for backup_engine in pillar.mysql.server.get("backup_engine", []) %}
83
84{%- if backup_engine.get("name", []) == "automysqlbackup" %}
85
86{%- if grains.osfullname in ['CentOS'] %}
87
88mysql_backup1_pkgs:
89 pkg.installed:
90 - names:
91 - pigz
92 - pbzip2
93 - cronie
94 - mailx
95
96{%- elif grains.osfullname in ['Ubuntu'] %}
97
98mysql_backup2_pkgs:
99 pkg.installed:
100 - names:
101 - mailutils
102 - pigz
103 - pbzip2
104
105{%- endif %}
106
107{%- if grains.osfullname in ['CentOS'] or grains.osfullname in ['Ubuntu'] %}
108
109mysql_backup_dirs:
110 file.directory:
111 - names:
112 - /root/mysql/scripts
113 - /root/mysql/data
114 - /etc/automysqlbackup
115 - mode: 700
116 - user: root
117 - group: root
118 - makedirs: true
119 - require:
120{%- if grains.osfullname in ['CentOS'] %}
121 - pkg: mysql_backup1_pkgs
122{%- elif grains.osfullname in ['Ubuntu'] %}
123 - pkg: mysql_backup2_pkgs
124{%- endif %}
125
126mysql_automysqlbackup_conf:
127 file.managed:
128 - name: /etc/automysqlbackup/automysqlbackup.conf
129 - source: salt://mysql/conf/automysqlbackup.conf
130 - mode: 644
131 - template: jinja
Filip Pytloun8980ef52016-05-24 17:11:50 +0200132 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200133 - file: mysql_backup_dirs
134
135mysql_automysqlbackup_script:
136 file.managed:
137 - name: /root/mysql/scripts/automysqlbackup
138 - source: salt://mysql/conf/automysqlbackup
139 - mode: 755
Filip Pytloun8980ef52016-05-24 17:11:50 +0200140 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200141 - file: mysql_backup_dirs
142
143mysql_automysqlbackup_cron:
144 file.managed:
145 - name: /etc/cron.daily/automysqlbackup
146 - source: salt://mysql/conf/automysqlbackup.cron
147 - mode: 755
148 - template: jinja
Filip Pytloun8980ef52016-05-24 17:11:50 +0200149 - require:
Filip Pytloun5b3c12e2015-10-06 16:28:32 +0200150 - file: mysql_backup_dirs
151
152{%- endif %}
153
154{%- endif %}
155
156{%- endfor %}
157