|
|
1
|
+#
|
|
|
2
|
+# Author:: Earth U (<sysadmin @ chromedia.com>)
|
|
|
3
|
+# Cookbook Name:: cfe-mariadb
|
|
|
4
|
+# Recipe:: schema
|
|
|
5
|
+#
|
|
|
6
|
+# Copyright 2016, Chromedia Far East, Inc.
|
|
|
7
|
+#
|
|
|
8
|
+# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
9
|
+# you may not use this file except in compliance with the License.
|
|
|
10
|
+# You may obtain a copy of the License at
|
|
|
11
|
+#
|
|
|
12
|
+# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
13
|
+#
|
|
|
14
|
+# Unless required by applicable law or agreed to in writing, software
|
|
|
15
|
+# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
16
|
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
17
|
+# See the License for the specific language governing permissions and
|
|
|
18
|
+# limitations under the License.
|
|
|
19
|
+#
|
|
|
20
|
+
|
|
|
21
|
+mysql2_chef_gem 'default' do
|
|
|
22
|
+ gem_version '0.4.4'
|
|
|
23
|
+ provider Chef::Provider::Mysql2ChefGem::Mariadb
|
|
|
24
|
+ action :install
|
|
|
25
|
+end
|
|
|
26
|
+
|
|
|
27
|
+# Prepare the needed databases and users.
|
|
|
28
|
+con = {
|
|
|
29
|
+ :host => node['mariadb']['mysqld']['bind_address'],
|
|
|
30
|
+ :port => node['mariadb']['mysqld']['port'],
|
|
|
31
|
+ :username => 'root',
|
|
|
32
|
+ :password => node['mariadb']['server_root_password']
|
|
|
33
|
+}
|
|
|
34
|
+node['cfe-mariadb']['db_map'].each do |dbx|
|
|
|
35
|
+
|
|
|
36
|
+ if dbx.is_a?(Array)
|
|
|
37
|
+ dbx_name = dbx[0]
|
|
|
38
|
+ dbx = dbx[1]
|
|
|
39
|
+ else
|
|
|
40
|
+ dbx_name = dbx[:db_name]
|
|
|
41
|
+ end
|
|
|
42
|
+
|
|
|
43
|
+ mysql_database dbx_name do
|
|
|
44
|
+ connection con
|
|
|
45
|
+ action :create
|
|
|
46
|
+ if dbx.has_key?(:char_set)
|
|
|
47
|
+ encoding dbx[:char_set]
|
|
|
48
|
+ end
|
|
|
49
|
+ if dbx.has_key?(:collate)
|
|
|
50
|
+ collation dbx[:collate]
|
|
|
51
|
+ end
|
|
|
52
|
+ end
|
|
|
53
|
+
|
|
|
54
|
+ mysql_database_user dbx[:db_user] do
|
|
|
55
|
+ connection con
|
|
|
56
|
+ password dbx[:db_pass]
|
|
|
57
|
+ database_name dbx_name
|
|
|
58
|
+ host '%'
|
|
|
59
|
+ privileges [:all]
|
|
|
60
|
+ action :grant
|
|
|
61
|
+ end
|
|
|
62
|
+end |
...
|
...
|
|