forked from sous-chefs/percona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplication.rb
33 lines (28 loc) · 924 Bytes
/
replication.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# Cookbook:: percona
# Recipe:: replication
#
require 'shellwords'
passwords = EncryptedPasswords.new(node, node['percona']['encrypted_data_bag'])
server = node['percona']['server']
replication_sql = server['replication']['replication_sql']
# define access grants
template replication_sql do
source 'replication.sql.erb'
variables(replication_password: passwords.replication_password)
owner 'root'
group 'root'
mode '0600'
sensitive true
only_if do
(server['replication']['host'] != '' || server['role'].include?('master')) && !::File.exist?(replication_sql)
end
end
root_pass = passwords.root_password.to_s
root_pass = Shellwords.escape(root_pass).prepend('-p') unless root_pass.empty?
execute 'mysql-set-replication' do
command "/usr/bin/mysql #{root_pass} < #{replication_sql}"
action :nothing
subscribes :run, resources("template[#{replication_sql}]"), :immediately
sensitive true
end