itamae-mitsurin 0.9 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/Rakefile +5 -5
- data/lib/itamae-mitsurin/logger.rb +16 -1
- data/lib/itamae-mitsurin/mitsurin.rb +0 -4
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +1 -0
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +101 -164
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +114 -176
- data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +61 -96
- data/lib/itamae-mitsurin/mitsurin/task_base.rb +72 -0
- data/lib/itamae-mitsurin/resource.rb +1 -0
- data/lib/itamae-mitsurin/resource/aws_ebs_volume.rb +65 -72
- data/lib/itamae-mitsurin/resource/aws_ec2_instance.rb +5 -5
- data/lib/itamae-mitsurin/resource/aws_route53_rrset.rb +13 -17
- data/lib/itamae-mitsurin/resource/aws_route53_rrset_alias.rb +13 -17
- data/lib/itamae-mitsurin/resource/file.rb +17 -12
- data/lib/itamae-mitsurin/version.txt +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e9e9d696a72e3f572493cd3988add3586c3c586
|
4
|
+
data.tar.gz: 205ae88f6ba75366e4ab0a5f445f71fc55e44e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6dd97e33fea2ad1546a8b86bcb99e98f491e1752b667b7c69e6cea698bdc0888e0f3411095a0ae9003634d3de67921a4b753b467b497d9de5ffd794ec95dc6
|
7
|
+
data.tar.gz: 1ee8b4c77729e89e235f8ecc0ccce49f7db1e76795ad4109ff427d0e9765b86de4fd36e6f4f332b894cc7ff6bb839e4bc798aba02af99c5243c62cb476f8e23d
|
data/README.md
CHANGED
@@ -13,8 +13,8 @@ Customized version of Itamae and plugin
|
|
13
13
|
|
14
14
|
```
|
15
15
|
$ gem install itamae-mitsurin
|
16
|
-
$ mkdir project_dir
|
17
|
-
$ cd project_dir
|
16
|
+
$ mkdir [project_dir]
|
17
|
+
$ cd [project_dir]
|
18
18
|
$ manaita init
|
19
19
|
```
|
20
20
|
|
@@ -34,6 +34,13 @@ aws_ebs_volume "ebs_name" do
|
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
37
|
+
## Wiki
|
38
|
+
- [itamae-mitsurin wiki](https://github.com/kammy1231/itamae-mitsurin/wiki/itamae-mitsurin-wiki)
|
39
|
+
|
40
|
+
## Reference
|
41
|
+
- [itamae wiki](https://github.com/itamae-kitchen/itamae/wiki)
|
42
|
+
- [Serverspec host_inventory](http://serverspec.org/host_inventory.html)
|
43
|
+
|
37
44
|
## Contributing
|
38
45
|
|
39
46
|
If you have a problem, please [create an issue](https://github.com/kammy1231/itamae-mitsurin) or a pull request.
|
data/Rakefile
CHANGED
@@ -25,11 +25,11 @@ Rake::TestTask.new
|
|
25
25
|
# t.test_files = FileList['test/test*.rb'].exclude('test/test_assoccoords.rb')
|
26
26
|
#end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
Rake::ExtensionTask.new do |ext|
|
29
|
+
ext.name = 'itamae-mitsurin'
|
30
|
+
ext.ext_dir = 'ext/'
|
31
|
+
ext.lib_dir = 'lib/'
|
32
|
+
end
|
33
33
|
|
34
34
|
Rake::PackageTask.new('itamae-mitsurin', "#{version}") do |t|
|
35
35
|
t.need_tar_gz = true
|
@@ -48,10 +48,25 @@ module ItamaeMitsurin
|
|
48
48
|
%w!debug info warn error fatal unknown!.each do |level|
|
49
49
|
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
50
50
|
def #{level}(msg)
|
51
|
-
super(
|
51
|
+
super(indent_msg(msg))
|
52
52
|
end
|
53
53
|
EOC
|
54
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def indent_msg(msg)
|
59
|
+
spaces = " " * indent_depth
|
60
|
+
case msg
|
61
|
+
when ::String
|
62
|
+
"#{spaces}#{msg}"
|
63
|
+
when ::Exception
|
64
|
+
"#{spaces}#{msg.message} (#{msg.class})\n" <<
|
65
|
+
(msg.backtrace || []).map {|f| "#{spaces}#{f}"}.join("\n")
|
66
|
+
else
|
67
|
+
"#{spaces}#{msg.inspect}"
|
68
|
+
end
|
69
|
+
end
|
55
70
|
end
|
56
71
|
|
57
72
|
class Formatter
|
@@ -2,10 +2,6 @@ require 'itamae-mitsurin/version'
|
|
2
2
|
require 'itamae-mitsurin/mitsurin/cli'
|
3
3
|
require 'itamae-mitsurin/mitsurin/creators'
|
4
4
|
require 'aws-sdk'
|
5
|
-
#require 'itamae-mitsurin/mitsurin/itamae_task'
|
6
|
-
#require 'itamae-mitsurin/mitsurin/serverspec_task'
|
7
|
-
#require 'itamae-mitsurin/mitsurin/itamae_with_git_task'
|
8
|
-
|
9
5
|
|
10
6
|
module ItamaeMitsurin
|
11
7
|
module Mitsurin
|
@@ -1,193 +1,130 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'highline'
|
3
|
+
require 'itamae-mitsurin/mitsurin/task_base'
|
3
4
|
include Rake::DSL if defined? Rake::DSL
|
4
5
|
|
5
|
-
module
|
6
|
+
module ItamaeMitsurin
|
6
7
|
module Mitsurin
|
7
8
|
class ItamaeTask
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
def deep_merge(other)
|
12
|
-
merger = lambda {|key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2}
|
13
|
-
self.merge(other, &merger)
|
14
|
-
end
|
15
|
-
|
16
|
-
def deep_merge!(other)
|
17
|
-
merger = lambda {|key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2}
|
18
|
-
self.merge!(other, &merger)
|
19
|
-
end
|
20
|
-
end
|
10
|
+
namespace :itamae do
|
11
|
+
Dir.glob("nodes/**/*.json").each do |node_file|
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
JSON.parse(File.read(node_file))['run_list'].each do |role|
|
25
|
-
roles << role.gsub(/role\[(.+)\]/, '\1') if /role\[(.+)\]/ === role
|
26
|
-
end
|
27
|
-
roles
|
28
|
-
end
|
13
|
+
bname = File.basename(node_file, '.json')
|
14
|
+
node_h = JSON.parse(File.read(node_file), symbolize_names: true)
|
29
15
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
16
|
+
desc "Itamae to #{bname}"
|
17
|
+
task node_h[:environments][:hostname].split(".")[0] do
|
18
|
+
begin
|
19
|
+
recipes = []
|
20
|
+
TaskBase.get_roles(node_file).each do |role|
|
21
|
+
recipes << TaskBase.get_recipes(role)
|
22
|
+
end
|
23
|
+
TaskBase.get_node_recipes(node_file).each do |recipe|
|
24
|
+
recipes << recipe
|
25
|
+
end
|
26
|
+
rescue Exception => e
|
27
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
28
|
+
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
35
29
|
else
|
36
|
-
recipes
|
30
|
+
recipes.flatten!
|
37
31
|
end
|
38
|
-
end
|
39
|
-
recipes
|
40
|
-
end
|
41
32
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
33
|
+
# get env attr
|
34
|
+
begin
|
35
|
+
env_set = node_h[:environments][:set]
|
36
|
+
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
37
|
+
rescue Exception => e
|
38
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
39
|
+
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
49
40
|
end
|
50
|
-
end
|
51
|
-
recipes
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.jq(*objs)
|
55
|
-
par = nil
|
56
|
-
objs.each {|obj| par = JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)}
|
57
|
-
return par
|
58
|
-
end
|
59
41
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
hl = HighLine.new
|
69
|
-
|
70
|
-
namespace :itamae do
|
71
|
-
Dir.glob("nodes/**/*.json").each do |node_file|
|
72
|
-
|
73
|
-
bname = File.basename(node_file, '.json')
|
74
|
-
node_h = JSON.parse(File.read(node_file), symbolize_names: true)
|
75
|
-
|
76
|
-
desc "Itamae to #{bname}"
|
77
|
-
task node_h[:environments][:hostname].split(".")[0] do
|
78
|
-
begin
|
79
|
-
recipes = []
|
80
|
-
get_roles(node_file).each do |role|
|
81
|
-
recipes << get_recipes(role)
|
82
|
-
end
|
83
|
-
get_node_recipes(node_file).each do |recipe|
|
84
|
-
recipes << recipe
|
85
|
-
end
|
86
|
-
rescue Exception => e
|
87
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
88
|
-
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
89
|
-
exit 1
|
42
|
+
# get recipes attr
|
43
|
+
recipe_attr_file = []
|
44
|
+
recipes.each do |recipe_h|
|
45
|
+
if recipe_h["#{recipe_h.keys.join}"].nil?
|
46
|
+
recipe_attr_file.insert 0,
|
47
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
|
90
48
|
else
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
# get env attr
|
95
|
-
begin
|
96
|
-
env_set = node_h[:environments][:set]
|
97
|
-
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
98
|
-
rescue Exception => e
|
99
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
100
|
-
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
101
|
-
exit 1
|
102
|
-
end
|
103
|
-
|
104
|
-
# get recipes attr
|
105
|
-
recipe_attr_file = []
|
106
|
-
recipes.each do |recipe_h|
|
107
|
-
if recipe_h["#{recipe_h.keys.join}"].nil?
|
108
|
-
recipe_attr_file.insert 0,
|
109
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
|
110
|
-
else
|
111
|
-
recipe_attr_file <<
|
112
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
113
|
-
end
|
49
|
+
recipe_attr_file <<
|
50
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
114
51
|
end
|
52
|
+
end
|
115
53
|
|
116
|
-
|
54
|
+
recipe_attr_file.flatten!
|
117
55
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
56
|
+
# recipes attr other=env
|
57
|
+
recipe_env_h_a = []
|
58
|
+
recipe_attr_file.each do |file|
|
59
|
+
recipe_h = JSON.parse(File.read(file), symbolize_names: true)
|
60
|
+
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
61
|
+
end
|
124
62
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
63
|
+
# recipe attr other=recipes_env
|
64
|
+
moto = recipe_env_h_a[0]
|
65
|
+
recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
|
66
|
+
recipe_env_h = moto
|
129
67
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
68
|
+
if recipe_env_h.nil?
|
69
|
+
# env attr other=node
|
70
|
+
node_env_h = env_h.deep_merge(node_h)
|
71
|
+
node_env_j = TaskBase.jq node_env_h
|
72
|
+
TaskBase.write_json(bname) {|file| file.puts node_env_j}
|
73
|
+
else
|
74
|
+
# recipe_env attr other=node
|
75
|
+
recipe_env_node_h = recipe_env_h.deep_merge(node_h)
|
76
|
+
recipe_env_node_j = TaskBase.jq recipe_env_node_h
|
77
|
+
TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
|
78
|
+
end
|
141
79
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
80
|
+
recipes << {'_base' => nil}
|
81
|
+
node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
|
82
|
+
node = node_property[:environments][:hostname]
|
83
|
+
ssh_user = node_property[:environments][:ssh_user]
|
84
|
+
ssh_password = node_property[:environments][:ssh_password]
|
85
|
+
sudo_password = node_property[:environments][:sudo_password]
|
86
|
+
ssh_port = node_property[:environments][:ssh_port]
|
87
|
+
ssh_key = node_property[:environments][:ssh_key]
|
88
|
+
|
89
|
+
ENV['TARGET_HOST'] = node
|
90
|
+
ENV['NODE_FILE'] = node_file
|
91
|
+
ENV['SSH_PASSWORD'] = ssh_password
|
92
|
+
ENV['SUDO_PASSWORD'] = sudo_password
|
93
|
+
|
94
|
+
command = "bundle exec itamae ssh"
|
95
|
+
command << " -h #{node}"
|
96
|
+
command << " -u #{ssh_user}"
|
97
|
+
command << " -p #{ssh_port}"
|
98
|
+
command << " -i keys/#{ssh_key}" unless ssh_key.nil?
|
99
|
+
command << " -j tmp-nodes/#{bname}.json"
|
100
|
+
command << " --shell=bash"
|
101
|
+
command << " --ask-password" unless ssh_password.nil?
|
102
|
+
command << " --dry-run" if ENV['dry-run'] == "true"
|
103
|
+
command << " -l debug" if ENV['debug'] == "true"
|
166
104
|
|
167
105
|
# recipe load to_command
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
106
|
+
command_recipe = []
|
107
|
+
recipes.each do |recipe_h|
|
108
|
+
if recipe_h["#{recipe_h.keys.join}"].nil?
|
109
|
+
command_recipe <<
|
110
|
+
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/default.rb").join}"
|
111
|
+
else
|
112
|
+
command_recipe <<
|
113
|
+
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join}"
|
177
114
|
end
|
178
|
-
command_recipe.sort_by! {|item| File.dirname(item)}
|
179
|
-
command << command_recipe.join
|
180
|
-
|
181
|
-
puts hl.color(%!Run Itamae to \"#{bname}\"!, :red)
|
182
|
-
puts hl.color(%!Role List to \"#{get_roles(node_file).join(", ")}\"!, :blue)
|
183
|
-
run_list_noti = []
|
184
|
-
command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
|
185
|
-
puts hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
186
|
-
puts hl.color(%!#{command}!, :white)
|
187
|
-
st = system command
|
188
|
-
exit 1 unless st
|
189
115
|
end
|
190
116
|
|
117
|
+
command_recipe.sort_by! {|item| File.dirname(item)}
|
118
|
+
command << command_recipe.join
|
119
|
+
|
120
|
+
puts TaskBase.hl.color(%!Run Itamae to \"#{bname}\"!, :red)
|
121
|
+
puts TaskBase.hl.color(%!Role List to \"#{TaskBase.get_roles(node_file).join(", ")}\"!, :blue)
|
122
|
+
run_list_noti = []
|
123
|
+
command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
|
124
|
+
puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
125
|
+
puts TaskBase.hl.color(%!#{command}!, :white)
|
126
|
+
st = system command
|
127
|
+
exit 1 unless st
|
191
128
|
end
|
192
129
|
end
|
193
130
|
end
|
@@ -2,6 +2,7 @@ require 'specinfra'
|
|
2
2
|
require 'json'
|
3
3
|
require 'highline'
|
4
4
|
require 'specinfra/helper/set'
|
5
|
+
require 'itamae-mitsurin/mitsurin/task_base'
|
5
6
|
include Specinfra::Helper::Set
|
6
7
|
include Rake::DSL if defined? Rake::DSL
|
7
8
|
|
@@ -9,201 +10,138 @@ module Itamae
|
|
9
10
|
module Mitsurin
|
10
11
|
class ItamaeTask
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
set :backend, :exec
|
14
|
+
|
15
|
+
namespace :itamae do
|
16
|
+
branches = Specinfra.backend.run_command('git branch')
|
17
|
+
branch = branches.stdout.split("\n").select {|a| /\*/ === a }
|
18
|
+
branch = branch.join.gsub(/\* (.+)/, '\1')
|
19
|
+
if branch == 'staging'
|
20
|
+
branch = 'staging/**'
|
21
|
+
elsif branch == 'master'
|
22
|
+
branch = 'production/**'
|
23
|
+
else
|
24
|
+
all = Dir.entries("nodes/")
|
25
|
+
all.delete_if {|d| /(^\.|staging|production|.json)/ === d }
|
26
|
+
branch = "{#{all.join(",")}}/**"
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
|
-
roles = []
|
27
|
-
JSON.parse(File.read(node_file))['run_list'].each do |role|
|
28
|
-
roles << role.gsub(/role\[(.+)\]/, '\1') if /role\[(.+)\]/ === role
|
29
|
-
end
|
30
|
-
roles
|
31
|
-
end
|
29
|
+
Dir.glob("nodes/#{branch}/*.json").each do |node_file|
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
JSON.parse(File.read("roles/#{role}.json"))['run_list'].each do |recipe|
|
36
|
-
if /recipe\[(.+)::(.+)\]/ === recipe
|
37
|
-
recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')}
|
38
|
-
else
|
39
|
-
recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
recipes
|
43
|
-
end
|
31
|
+
bname = File.basename(node_file, '.json')
|
32
|
+
node_h = JSON.parse(File.read(node_file), symbolize_names: true)
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
desc "Itamae to #{bname}"
|
35
|
+
task node_h[:environments][:hostname].split(".")[0] do
|
36
|
+
begin
|
37
|
+
recipes = []
|
38
|
+
TaskBase.get_roles(node_file).each do |role|
|
39
|
+
recipes << TaskBase.get_recipes(role)
|
40
|
+
end
|
41
|
+
TaskBase.get_node_recipes(node_file).each do |recipe|
|
42
|
+
recipes << recipe
|
43
|
+
end
|
44
|
+
rescue Exception => e
|
45
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
46
|
+
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
50
47
|
else
|
51
|
-
recipes
|
48
|
+
recipes.flatten!
|
52
49
|
end
|
53
|
-
end
|
54
|
-
recipes
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.jq(*objs)
|
58
|
-
par = nil
|
59
|
-
objs.each {|obj| par = JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)}
|
60
|
-
return par
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.write_json(filename)
|
64
|
-
File.open "tmp-nodes/#{filename}.json", 'w' do |f|
|
65
|
-
f.flock File::LOCK_EX
|
66
|
-
yield f
|
67
|
-
f.flock File::LOCK_UN
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
hl = HighLine.new
|
72
|
-
|
73
|
-
set :backend, :exec
|
74
50
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
branch = 'production/**'
|
83
|
-
else
|
84
|
-
branch = 'other/**'
|
51
|
+
# get env attr
|
52
|
+
begin
|
53
|
+
env_set = node_h[:environments][:set]
|
54
|
+
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
55
|
+
rescue Exception => e
|
56
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
57
|
+
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
85
58
|
end
|
86
59
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
task node_h[:environments][:hostname].split(".")[0] do
|
94
|
-
begin
|
95
|
-
recipes = []
|
96
|
-
get_roles(node_file).each do |role|
|
97
|
-
recipes << get_recipes(role)
|
98
|
-
end
|
99
|
-
get_node_recipes(node_file).each do |recipe|
|
100
|
-
recipes << recipe
|
101
|
-
end
|
102
|
-
rescue Exception => e
|
103
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
104
|
-
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
105
|
-
exit 1
|
60
|
+
# get recipe attr
|
61
|
+
recipe_attr_file = []
|
62
|
+
recipes.each do |recipe_h|
|
63
|
+
if recipe_h["#{recipe_h.keys.join}"].nil?
|
64
|
+
recipe_attr_file.insert 0,
|
65
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
|
106
66
|
else
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
# get env attr
|
111
|
-
begin
|
112
|
-
env_set = node_h[:environments][:set]
|
113
|
-
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
114
|
-
rescue Exception => e
|
115
|
-
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
116
|
-
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
117
|
-
exit 1
|
67
|
+
recipe_attr_file <<
|
68
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
118
69
|
end
|
70
|
+
end
|
119
71
|
|
120
|
-
|
121
|
-
recipe_attr_file = []
|
122
|
-
recipes.each do |recipe_h|
|
123
|
-
if recipe_h["#{recipe_h.keys.join}"].nil?
|
124
|
-
recipe_attr_file.insert 0,
|
125
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
|
126
|
-
else
|
127
|
-
recipe_attr_file <<
|
128
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
129
|
-
end
|
130
|
-
end
|
72
|
+
recipe_attr_file.flatten!
|
131
73
|
|
132
|
-
|
74
|
+
# recipe attr other=env
|
75
|
+
recipe_env_h_a = []
|
76
|
+
recipe_attr_file.each do |file|
|
77
|
+
recipe_h = JSON.parse(File.read(file), symbolize_names: true)
|
78
|
+
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
79
|
+
end
|
133
80
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
139
|
-
end
|
81
|
+
# recipe attr other=recipes
|
82
|
+
moto = recipe_env_h_a[0]
|
83
|
+
recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
|
84
|
+
recipe_env_h = moto
|
140
85
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
86
|
+
if recipe_env_h.nil?
|
87
|
+
# node attr other=env
|
88
|
+
node_env_h = env_h.deep_merge(node_h)
|
89
|
+
node_env_j = TaskBase.jq node_env_h
|
90
|
+
TaskBase.write_json(bname) {|file| file.puts node_env_j}
|
91
|
+
else
|
92
|
+
# node attr other=recipe_env
|
93
|
+
recipe_env_node_h = recipe_env_h.deep_merge(node_h)
|
94
|
+
recipe_env_node_j = TaskBase.jq recipe_env_node_h
|
95
|
+
TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
|
96
|
+
end
|
145
97
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
98
|
+
recipes << {'_base' => nil}
|
99
|
+
node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
|
100
|
+
node = node_property[:environments][:hostname]
|
101
|
+
ssh_user = node_property[:environments][:ssh_user]
|
102
|
+
ssh_password = node_property[:environments][:ssh_password]
|
103
|
+
sudo_password = node_property[:environments][:sudo_password]
|
104
|
+
ssh_port = node_property[:environments][:ssh_port]
|
105
|
+
ssh_key = node_property[:environments][:ssh_key]
|
106
|
+
|
107
|
+
ENV['TARGET_HOST'] = node
|
108
|
+
ENV['NODE_FILE'] = node_file
|
109
|
+
ENV['SSH_PASSWORD'] = ssh_password
|
110
|
+
ENV['SUDO_PASSWORD'] = sudo_password
|
111
|
+
|
112
|
+
command = "bundle exec itamae ssh"
|
113
|
+
command << " -h #{node}"
|
114
|
+
command << " -u #{ssh_user}"
|
115
|
+
command << " -p #{ssh_port}"
|
116
|
+
command << " -i keys/#{ssh_key}" unless ssh_key.nil?
|
117
|
+
command << " -j tmp-nodes/#{bname}.json"
|
118
|
+
command << " --shell=bash"
|
119
|
+
command << " --ask-password" unless ssh_password.nil?
|
120
|
+
command << " --dry-run" if ENV['dry-run'] == "true"
|
121
|
+
command << " -l debug" if ENV['debug'] == "true"
|
122
|
+
|
123
|
+
# recipe load to_command
|
124
|
+
command_recipe = []
|
125
|
+
recipes.each do |recipe_h|
|
126
|
+
if recipe_h["#{recipe_h.keys.join}"].nil?
|
127
|
+
command_recipe <<
|
128
|
+
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/default.rb").join}"
|
151
129
|
else
|
152
|
-
|
153
|
-
|
154
|
-
recipe_env_node_j = jq recipe_env_node_h
|
155
|
-
write_json(bname) {|file| file.puts recipe_env_node_j}
|
156
|
-
end
|
157
|
-
|
158
|
-
recipes << {'_base' => nil}
|
159
|
-
node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
|
160
|
-
node = node_property[:environments][:hostname]
|
161
|
-
ssh_user = node_property[:environments][:ssh_user]
|
162
|
-
ssh_password = node_property[:environments][:ssh_password]
|
163
|
-
sudo_password = node_property[:environments][:sudo_password]
|
164
|
-
ssh_port = node_property[:environments][:ssh_port]
|
165
|
-
ssh_key = node_property[:environments][:ssh_key]
|
166
|
-
|
167
|
-
ENV['TARGET_HOST'] = node
|
168
|
-
ENV['NODE_FILE'] = node_file
|
169
|
-
ENV['SSH_PASSWORD'] = ssh_password
|
170
|
-
ENV['SUDO_PASSWORD'] = sudo_password
|
171
|
-
|
172
|
-
command = "bundle exec itamae ssh"
|
173
|
-
command << " -h #{node}"
|
174
|
-
command << " -u #{ssh_user}"
|
175
|
-
command << " -p #{ssh_port}"
|
176
|
-
command << " -i keys/#{ssh_key}" unless ssh_key.nil?
|
177
|
-
command << " -j tmp-nodes/#{bname}.json"
|
178
|
-
command << " --shell=bash"
|
179
|
-
command << " --ask-password" unless ssh_password.nil?
|
180
|
-
command << " --dry-run" if ENV['dry_run'] == "true"
|
181
|
-
command << " -l debug" if ENV['debug'] == "true"
|
182
|
-
|
183
|
-
# recipe load to_command
|
184
|
-
command_recipe = []
|
185
|
-
recipes.each do |recipe_h|
|
186
|
-
if recipe_h["#{recipe_h.keys.join}"].nil?
|
187
|
-
command_recipe <<
|
188
|
-
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/default.rb").join}"
|
189
|
-
else
|
190
|
-
command_recipe <<
|
191
|
-
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join}"
|
192
|
-
end
|
130
|
+
command_recipe <<
|
131
|
+
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join}"
|
193
132
|
end
|
194
|
-
command_recipe.sort_by! {|item| File.dirname(item)}
|
195
|
-
command << command_recipe.join
|
196
|
-
|
197
|
-
puts hl.color(%!Run Itamae to \"#{bname}\"!, :red)
|
198
|
-
puts hl.color(%!Role List to \"#{get_roles(node_file).join(", ")}\"!, :blue)
|
199
|
-
run_list_noti = []
|
200
|
-
command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
|
201
|
-
puts hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
202
|
-
puts hl.color(%!#{command}!, :white)
|
203
|
-
st = system command
|
204
|
-
exit 1 unless st
|
205
133
|
end
|
206
|
-
|
134
|
+
command_recipe.sort_by! {|item| File.dirname(item)}
|
135
|
+
command << command_recipe.join
|
136
|
+
|
137
|
+
puts TaskBase.hl.color(%!Run Itamae to \"#{bname}\"!, :red)
|
138
|
+
puts TaskBase.hl.color(%!Role List to \"#{TaskBase.get_roles(node_file).join(", ")}\"!, :blue)
|
139
|
+
run_list_noti = []
|
140
|
+
command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
|
141
|
+
puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
142
|
+
puts TaskBase.hl.color(%!#{command}!, :white)
|
143
|
+
st = system command
|
144
|
+
exit 1 unless st
|
207
145
|
end
|
208
146
|
end
|
209
147
|
end
|