itamae-plugin-recipe-kzyty_mysql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe07de564d36d128c0614b7ef9c1be53a3410400
4
+ data.tar.gz: 21b3267271de835a69aedff5308065efca5a320e
5
+ SHA512:
6
+ metadata.gz: ae98c8ccd7b94ccd7301fbce24d8943a07f5efd7070dcbca7f5cd3c7d5492e800a2a6b5c30c958f5ecfadc3574b04255d902aa8e476e944682ac5355385fcb9c
7
+ data.tar.gz: dcd56c87afd03da0de6c260ce590b72effbee279d9628c5645266fa35b3b7a0e03c20b18ac7d4019ccf6d9e8547ce409f99ddbabe33a8f3a78776060139b700c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ .tags*
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ DisplayCopNames: true
5
+
6
+ Style/AsciiComments:
7
+ Enabled: false
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Metrics/LineLength:
13
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itamae-plugin-recipe-kzyty_mysql.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Takahito Nakano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Itamae::Plugin::Recipe::KzytyMysql
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/itamae/plugin/recipe/mysql`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Forked for temporarily gem
8
+
9
+ https://github.com/ponko2/itamae-plugin-recipe-mysql
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'itamae-plugin-recipe-kzyty_mysql'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install itamae-plugin-recipe-kzyty_mysql
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/itamae-plugin-recipe-kzyty_mysql/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'itamae/plugin/recipe/kzyty_mysql'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'itamae/plugin/recipe/kzyty_mysql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'itamae-plugin-recipe-kzyty_mysql'
8
+ spec.version = Itamae::Plugin::Recipe::KzytyMysql::VERSION
9
+ spec.authors = ['Taiyo Kojima']
10
+ spec.email = ['kozyty@gmail.com']
11
+
12
+ spec.summary = 'Itamae plugin to install mysql.'
13
+ spec.description = 'Itamae plugin to install mysql by package.'
14
+ spec.homepage = 'https://github.com/ponko2/itamae-plugin-recipe-kzyty_mysql'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'itamae', '~> 1.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.9'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'itamae/plugin/recipe/kzyty_mysql/version'
2
+
3
+ module Itamae
4
+ module Plugin
5
+ module Recipe
6
+ module KzytyMysql
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ %w(mysql-client libmysqlclient-dev).each do |p|
2
+ package p do
3
+ action :install
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require 'shellwords'
2
+
3
+ node.validate! do
4
+ {
5
+ kzyty_mysql: {
6
+ server_root_password: string,
7
+ databases: array_of({
8
+ name: string,
9
+ charset: string,
10
+ collate: string,
11
+ privileges: array_of({
12
+ types: array_of(string),
13
+ user: string,
14
+ host: string,
15
+ password: string
16
+ })
17
+ })
18
+ }
19
+ }
20
+ end
21
+
22
+ template '/etc/mysql_databases.sql' do
23
+ owner 'root'
24
+ group 'root'
25
+ mode '0600'
26
+ notifies :run, 'execute[create databases]', :immediately
27
+ end
28
+
29
+ execute 'create databases' do
30
+ if node[:kzyty_mysql][:server_root_password].empty?
31
+ password_string = ''
32
+ else
33
+ password_string = '-p' + Shellwords.escape(node[:kzyty_mysql][:server_root_password])
34
+ end
35
+
36
+ cmd = '/bin/cat /etc/mysql_databases.sql | /usr/bin/mysql'
37
+ cmd << " -u root #{password_string}"
38
+ command cmd
39
+ action :nothing
40
+ end
@@ -0,0 +1,57 @@
1
+ require 'shellwords'
2
+
3
+ node.validate! do
4
+ {
5
+ kzyty_mysql: {
6
+ server_root_password: string,
7
+ server_repl_password: optional(string),
8
+ allow_remote_root: optional(boolean),
9
+ remove_anonymous_users: optional(boolean),
10
+ remove_test_database: optional(boolean),
11
+ root_network_acl: optional(array_of(string))
12
+ }
13
+ }
14
+ end
15
+
16
+ node.reverse_merge!(
17
+ kzyty_mysql: {
18
+ allow_remote_root: false,
19
+ remove_anonymous_users: false,
20
+ remove_test_database: false,
21
+ root_network_acl: []
22
+ }
23
+ )
24
+
25
+ package 'mysql-server'
26
+
27
+ service 'mysql' do
28
+ action [:start, :enable]
29
+ end
30
+
31
+ execute 'assign root password' do
32
+ cmd = '/usr/bin/mysqladmin'
33
+ cmd << ' -u root password '
34
+ cmd << Shellwords.escape(node[:kzyty_mysql][:server_root_password])
35
+ command cmd
36
+ only_if "/usr/bin/mysql -u root -e 'show databases;'"
37
+ end
38
+
39
+ template '/etc/mysql_grant.sql' do
40
+ owner 'root'
41
+ group 'root'
42
+ mode '0600'
43
+ notifies :run, 'execute[install grants]'
44
+ end
45
+
46
+ execute 'install grants' do
47
+ if node[:kzyty_mysql][:server_root_password].empty?
48
+ password_string = ''
49
+ else
50
+ password_string = '-p' + Shellwords.escape(node[:kzyty_mysql][:server_root_password])
51
+ end
52
+
53
+ cmd = '/bin/cat /etc/mysql_grants.sql | /usr/bin/mysql'
54
+ cmd << " -u root #{password_string}"
55
+ command cmd
56
+ action :nothing
57
+ end
@@ -0,0 +1,8 @@
1
+ <% node[:kzyty_mysql][:databases].each do |database| %>
2
+ CREATE DATABASE IF NOT EXISTS `<%= database[:name] %>` DEFAULT CHARACTER SET <%= database[:charset] %> DEFAULT COLLATE <%= database[:collate] %>;
3
+ <% database[:privileges].each do |p| -%>
4
+ <% unless p[:types].empty? -%>
5
+ GRANT <%= p[:types].join(',') %> ON `<%= database[:name] %>`.* TO '<%= p[:user] %>'@'<%= p[:host] %>' IDENTIFIED BY '<%= p[:password] %>' WITH GRANT OPTION;
6
+ <% end -%>
7
+ <% end -%>
8
+ <% end -%>
@@ -0,0 +1,26 @@
1
+ <% if node[:kzyty_mysql][:server_repl_password] -%>
2
+ GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '<%= node[:kzyty_mysql][:server_repl_password] %>';
3
+ <% end -%>
4
+
5
+ <% if node[:kzyty_mysql][:allow_remote_root] -%>
6
+ GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node[:kzyty_mysql][:server_root_password] %>' WITH GRANT OPTION;
7
+ <% else %>
8
+ DELETE FROM kzyty_mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
9
+ UPDATE kzyty_mysql.user SET Password=PASSWORD('<%= node[:kzyty_mysql][:server_root_password] %>') WHERE User='root';
10
+ <% end -%>
11
+
12
+ <% if node[:kzyty_mysql][:remove_anonymous_users] -%>
13
+ DELETE FROM kzyty_mysql.user WHERE User='';
14
+ <% end -%>
15
+
16
+ <% if node[:kzyty_mysql][:remove_test_database] -%>
17
+ DROP DATABASE IF EXISTS test;
18
+ DELETE FROM kzyty_mysql.db WHERE Db='test' OR Db='test\_%';
19
+ <% end -%>
20
+
21
+ SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<%= node[:kzyty_mysql][:server_root_password] %>');
22
+ SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('<%= node[:kzyty_mysql][:server_root_password] %>');
23
+
24
+ <% node[:kzyty_mysql][:root_network_acl].each do |acl| -%>
25
+ GRANT ALL PRIVILEGES ON *.* TO 'root'@'<%= acl %>' IDENTIFIED BY '<%= node[:kzyty_mysql][:server_root_password] %>' WITH GRANT OPTION;
26
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ module Itamae
2
+ module Plugin
3
+ module Recipe
4
+ module KzytyMysql
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ <% node[:kzyty_mysql][:databases].each do |database| %>
2
+ CREATE DATABASE IF NOT EXISTS `<%= database[:name] %>` DEFAULT CHARACTER SET <%= database[:charset] %> DEFAULT COLLATE <%= database[:collate] %>;
3
+ <% database[:privileges].each do |p| -%>
4
+ <% unless p[:types].empty? -%>
5
+ GRANT <%= p[:types].join(',') %> ON `<%= database[:name] %>`.* TO '<%= p[:user] %>'@'<%= p[:host] %>' IDENTIFIED BY '<%= p[:password] %>' WITH GRANT OPTION;
6
+ <% end -%>
7
+ <% end -%>
8
+ <% end -%>
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-plugin-recipe-kzyty_mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taiyo Kojima
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: itamae
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Itamae plugin to install mysql by package.
56
+ email:
57
+ - kozyty@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - itamae-plugin-recipe-kzyty_mysql.gemspec
72
+ - lib/itamae/plugin/recipe/kzyty_mysql.rb
73
+ - lib/itamae/plugin/recipe/kzyty_mysql/client.rb
74
+ - lib/itamae/plugin/recipe/kzyty_mysql/databases.rb
75
+ - lib/itamae/plugin/recipe/kzyty_mysql/server.rb
76
+ - lib/itamae/plugin/recipe/kzyty_mysql/templates/etc/mysql_databases.sql.erb
77
+ - lib/itamae/plugin/recipe/kzyty_mysql/templates/etc/mysql_grant.sql.erb
78
+ - lib/itamae/plugin/recipe/kzyty_mysql/version.rb
79
+ - lib/itamae/plugin/recipe/mysql/templates/etc/mysql_databases.sql.erb
80
+ homepage: https://github.com/ponko2/itamae-plugin-recipe-kzyty_mysql
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Itamae plugin to install mysql.
104
+ test_files: []