blob: a73284124c62ad9b2623d6675790a80dce6922d4 [file] [log] [blame]
Ales Komarekcba48ac2015-04-30 11:40:44 +02001{%- from "galera/map.jinja" import master with context %}
2{%- if master.enabled %}
3
Ales Komarekcba48ac2015-04-30 11:40:44 +02004galera_packages:
5 pkg.installed:
6 - names: {{ master.pkgs }}
7
8galera_log_dir:
9 file.directory:
10 - name: /var/log/mysql
11 - makedirs: true
12 - mode: 755
13 - require:
14 - pkg: galera_packages
15
Ales Komarek90da78d2015-04-30 16:01:11 +020016galera_init_script:
17 file.managed:
18 - name: /etc/init.d/mysql
19 - source: salt://galera/files/mysql
20 - mode: 755
21 - require:
22 - pkg: galera_packages
23
Ales Komarekcf92b4e2015-04-30 16:52:21 +020024{%- if salt['cmd.run']('test -e /root/.galera_bootstrap; echo $?') != '0' %}
Ales Komarekcba48ac2015-04-30 11:40:44 +020025
26galera_bootstrap_temp_config:
27 file.managed:
28 - name: {{ master.config }}
Ales Komarek1fe9c702015-04-30 15:46:37 +020029 - source: salt://galera/files/my.cnf.bootstrap
Ales Komarekcba48ac2015-04-30 11:40:44 +020030 - mode: 644
31 - template: jinja
32 - require:
33 - pkg: galera_packages
Ales Komarek90da78d2015-04-30 16:01:11 +020034 - file: galera_init_script
Ales Komarekcba48ac2015-04-30 11:40:44 +020035
36galera_bootstrap_start_service:
37 service.running:
38 - name: mysql
39 - require:
40 - file: galera_bootstrap_temp_config
41
42galera_bootstrap_set_root_password:
43 cmd.run:
44 - name: mysqladmin password "{{ master.admin.password }}"
45 - require:
46 - service: galera_bootstrap_start_service
47
48mysql_bootstrap_update_maint_password:
49 cmd.run:
50 - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
51 - require:
52 - cmd: galera_bootstrap_set_root_password
53
Ales Komarek41517c42015-04-30 15:58:19 +020054galera_bootstrap_stop_service:
Ales Komarekcba48ac2015-04-30 11:40:44 +020055 service.dead:
Ales Komarek41517c42015-04-30 15:58:19 +020056 - name: {{ master.service }}
Ales Komarekcba48ac2015-04-30 11:40:44 +020057 - require:
58 - cmd: mysql_bootstrap_update_maint_password
59
60galera_bootstrap_init_config:
61 file.managed:
62 - name: {{ master.config }}
Ales Komarek41517c42015-04-30 15:58:19 +020063 - source: salt://galera/files/my.cnf.init
Ales Komarekcba48ac2015-04-30 11:40:44 +020064 - mode: 644
65 - template: jinja
66 - require:
67 - service: galera_bootstrap_stop_service
68
Ales Komarek41517c42015-04-30 15:58:19 +020069galera_bootstrap_start_service_final:
70 service.running:
71 - name: {{ master.service }}
72 - require:
73 - file: galera_bootstrap_init_config
74
Ales Komarekb2824102015-04-30 15:43:17 +020075galera_bootstrap_finish_flag:
Ales Komarekcba48ac2015-04-30 11:40:44 +020076 file.touch:
Ales Komarek22a43f52015-04-30 16:03:27 +020077 - name: /root/.galera_bootstrap
Ales Komarekcba48ac2015-04-30 11:40:44 +020078 - require:
Ales Komarek41517c42015-04-30 15:58:19 +020079 - service: galera_bootstrap_start_service_final
Ales Komarekcba48ac2015-04-30 11:40:44 +020080 - watch_in:
Ales Komarek41517c42015-04-30 15:58:19 +020081 - file: galera_config
Ales Komarekcba48ac2015-04-30 11:40:44 +020082
83{%- endif %}
84
Ales Komarek41517c42015-04-30 15:58:19 +020085galera_config:
86 file.managed:
87 - name: {{ master.config }}
88 - source: salt://galera/files/my.cnf
89 - mode: 644
90 - template: jinja
91 - require_in:
92 - service: galera_service
93
Ales Komarekcba48ac2015-04-30 11:40:44 +020094galera_service:
95 service.running:
96 - name: {{ master.service }}
97 - enable: true
98 - reload: true
99
100{%- endif %}