blob: 0d6572b53bac7464edf2a407433499e5508c9069 [file] [log] [blame]
Ales Komarekcf92b4e2015-04-30 16:52:21 +02001{%- if pillar.get('mysql', {}).server is defined %}
2
3{%- set server = pillar.mysql.server %}
4
5{%- for database_name, database in server.get('database', {}).iteritems() %}
6
7mysql_database_{{ database_name }}:
8 mysql_database.present:
9 - name: {{ database_name }}
Ales Komarekcf92b4e2015-04-30 16:52:21 +020010
11{%- for user in database.users %}
12
13mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
14 mysql_user.present:
15 - host: '{{ user.host }}'
16 - name: '{{ user.name }}'
17 - password: {{ user.password }}
Ales Komarekcf92b4e2015-04-30 16:52:21 +020018
19mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
20 mysql_grants.present:
21 - grant: {{ user.rights }}
22 - database: '{{ database_name }}.*'
23 - user: '{{ user.name }}'
24 - host: '{{ user.host }}'
25 - require:
26 - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
27 - mysql_database: mysql_database_{{ database_name }}
28
29{%- endfor %}
30
31{%- if database.initial_data is defined %}
32
33/root/mysql/scripts/restore_{{ database_name }}.sh:
34 file.managed:
35 - source: salt://mysql/conf/restore.sh
36 - mode: 770
37 - template: jinja
38 - defaults:
39 database_name: {{ database_name }}
40 - require:
41 - file: mysql_dirs
42 - mysql_database: mysql_database_{{ database_name }}
43
44restore_mysql_database_{{ database_name }}:
45 cmd.run:
46 - name: /root/mysql/scripts/restore_{{ database_name }}.sh
47 - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
48 - cwd: /root
49 - require:
50 - file: /root/mysql/scripts/restore_{{ database_name }}.sh
51
52{%- endif %}
53
54{%- endfor %}
55
56{%- for user in server.get('users', []) %}
57
58mysql_user_{{ user.name }}_{{ user.host }}:
59 mysql_user.present:
60 - host: '{{ user.host }}'
61 - name: '{{ user.name }}'
62 {%- if user.password is defined %}
63 - password: {{ user.password }}
64 {%- else %}
65 - allow_passwordless: True
66 {%- endif %}
67
68{%- endfor %}
69
70{%- endif %}