blob: e50f0b674b71a13ec5faaa71f7b7fff0240dbb55 [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 }}
10 - require:
11 {% if cluster.enabled %}
12 - cmd: mysql_cluster_init
13 {% else %}
14 - service: mysql_service
15 {% endif %}
16
17{%- for user in database.users %}
18
19mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
20 mysql_user.present:
21 - host: '{{ user.host }}'
22 - name: '{{ user.name }}'
23 - password: {{ user.password }}
24 - require:
25 {% if cluster.enabled %}
26 - cmd: mysql_cluster_init
27 {% else %}
28 - service: mysql_service
29 {% endif %}
30
31mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
32 mysql_grants.present:
33 - grant: {{ user.rights }}
34 - database: '{{ database_name }}.*'
35 - user: '{{ user.name }}'
36 - host: '{{ user.host }}'
37 - require:
38 - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
39 - mysql_database: mysql_database_{{ database_name }}
40
41{%- endfor %}
42
43{%- if database.initial_data is defined %}
44
45/root/mysql/scripts/restore_{{ database_name }}.sh:
46 file.managed:
47 - source: salt://mysql/conf/restore.sh
48 - mode: 770
49 - template: jinja
50 - defaults:
51 database_name: {{ database_name }}
52 - require:
53 - file: mysql_dirs
54 - mysql_database: mysql_database_{{ database_name }}
55
56restore_mysql_database_{{ database_name }}:
57 cmd.run:
58 - name: /root/mysql/scripts/restore_{{ database_name }}.sh
59 - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
60 - cwd: /root
61 - require:
62 - file: /root/mysql/scripts/restore_{{ database_name }}.sh
63
64{%- endif %}
65
66{%- endfor %}
67
68{%- for user in server.get('users', []) %}
69
70mysql_user_{{ user.name }}_{{ user.host }}:
71 mysql_user.present:
72 - host: '{{ user.host }}'
73 - name: '{{ user.name }}'
74 {%- if user.password is defined %}
75 - password: {{ user.password }}
76 {%- else %}
77 - allow_passwordless: True
78 {%- endif %}
79
80{%- endfor %}
81
82{%- endif %}