kondate 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da91e530d9040e3ffeeeaa4d21c6f7607594e106
4
- data.tar.gz: 62bf80a32d837bd0bdc71f3964ee05141613c68d
3
+ metadata.gz: 38160e964f7ea99cbd0bc387cc9309c27c3a442e
4
+ data.tar.gz: 1ea9ea5b11e0e70d80f1894c682c0cd156dcbcba
5
5
  SHA512:
6
- metadata.gz: 3924f100dbdcfccc78ca19ae4e62bbf5bcfafb5e57af8b5eb5dfc4377459f2da6307fb85e7acd06abc336426a4b44f22c2a88e6376e6c59b6d66cbbae5ccb8cc
7
- data.tar.gz: 4d5a72fffa375a632c7a9b4b30cf25a880ad0cf194ec0b0dcde553b38ad281c7fa98c65936be5e8766d034a632f19b2535314c3aaedbab02ba780ad2a38600ca
6
+ metadata.gz: 3c1385a0f8868aea7ce912b88cb36576d23fefc3e8a7f6347fa66f0653a495b35f30d456b72a3b810ab397b3f6a19d57bf91084f674e593783bba89b0190015d
7
+ data.tar.gz: d7eadd64d34d4842561a4e5659a07048da0574740688a6d939d2d8efc6fa7e0066b9a70fd9b1558b568ca901245e17d7d99c1ef1dde2ccbae3de99a9a8c34794
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.3.3 (2016-11-20)
2
+
3
+ Changes:
4
+
5
+ * kondate init now requires a target_dir argument, not an option anymore
6
+
1
7
  # 0.3.2 (2016-11-18)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  Generate a template directory tree:
26
26
 
27
27
  ```
28
- $ bundle exec kondate init [target_dir .]
28
+ $ bundle exec kondate init .
29
29
  ```
30
30
 
31
31
  Run itamae:
@@ -40,6 +40,18 @@ Run serverspec:
40
40
  $ bundle exec kondate serverspec <host>
41
41
  ```
42
42
 
43
+ Run itamae for multiple hosts of a given role in parallel:
44
+
45
+ ```
46
+ $ bundle exec kondate itamae-role <role>
47
+ ```
48
+
49
+ Run serverspec for multiple hosts of a given role in parallel:
50
+
51
+ ```
52
+ $ bundle exec kondate serverspec-role <role>
53
+ ```
54
+
43
55
  ## Configuration
44
56
 
45
57
  `kondate init` provides a template directory tree such as:
@@ -50,12 +62,12 @@ $ bundle exec kondate serverspec <host>
50
62
  ├── bootstrap.rb # itamae bootstrap
51
63
  ├── hosts.yml # manages hostnames and its roles
52
64
  ├── properties # manages run_lists and attributes
53
- │   ├── nodes # host specific properties (deprecated)
65
+ │   ├── nodes # host specific properties
54
66
  │   ├── roles # role properties
55
67
  │   └── environments # environment properties
56
68
  ├── secrets # manages secrets attributes such as passwords
57
69
  │   └── properties
58
- │   ├── nodes (deprecated)
70
+ │   ├── nodes
59
71
  │   ├── roles
60
72
  │   └── environments
61
73
  ├── recipes # itamae recipes
@@ -76,13 +88,13 @@ The default .kondate.conf looks like below:
76
88
 
77
89
  ```
78
90
  middlware_recipes_dir: recipes/middleware
79
- roles_recipes_dir: recipes/roles (deprecated)
91
+ roles_recipes_dir: recipes/roles
80
92
  middleware_recipes_serverspec_dir: spec/middleware
81
93
  roles_recipes_serverspec_dir: spec/roles
82
- nodes_properties_dir: properties/nodes (deprecated)
94
+ nodes_properties_dir: properties/nodes
83
95
  roles_properties_dir: properties/roles
84
96
  environments_properties_dir: properties/environments
85
- secret_nodes_properties_dir: secrets/properties/nodes (deprecated)
97
+ secret_nodes_properties_dir: secrets/properties/nodes
86
98
  secret_roles_properties_dir: secrets/properties/roles
87
99
  secret_environments_properties_dir: secrets/properties/environments
88
100
  plugin_dir: lib
@@ -174,7 +186,7 @@ Secret properties are places to write confidential attributes.
174
186
  ```
175
187
  ├── secrets # manages secrets attributes such as passwords
176
188
  │   └── properties
177
- │   ├── nodes (deprecated)
189
+ │   ├── nodes
178
190
  │   ├── roles
179
191
  │   └── environments
180
192
  ```
@@ -300,12 +312,12 @@ module Kondate
300
312
  raise ConfigError.new('file: path is not configured') unless config.path
301
313
  @path = config.path
302
314
 
303
- @roles_of_hosts = YAML.load_file(@path)
304
- @hosts_of_roles = {}
305
- @roles_of_hosts.each do |host, roles|
315
+ @roles_of = YAML.load_file(@path)
316
+ @hosts_of = {}
317
+ @roles_of.each do |host, roles|
306
318
  roles.each do |role|
307
- @hosts_of_roles[role] ||= []
308
- @hosts_of_roles[role] << host
319
+ @hosts_of[role] ||= []
320
+ @hosts_of[role] << host
309
321
  end
310
322
  end
311
323
  end
@@ -319,7 +331,7 @@ module Kondate
319
331
  # @param [String] host hostname
320
332
  # @return [Array] array of roles
321
333
  def get_roles(host)
322
- @roles_of_hosts[host]
334
+ @roles_of[host]
323
335
  end
324
336
 
325
337
  # @param [String] role role
@@ -327,7 +339,7 @@ module Kondate
327
339
  #
328
340
  # Available from kondate >= 0.3.0
329
341
  def get_hosts(role)
330
- @hosts_of_roles[role]
342
+ @hosts_of[role]
331
343
  end
332
344
 
333
345
  # Optional
@@ -361,7 +373,7 @@ host_plugin:
361
373
  ## Development
362
374
 
363
375
  ```
364
- bundle exec exe/kondate init
376
+ bundle exec exe/kondate init .
365
377
  vagrant up
366
378
  ```
367
379
 
data/lib/kondate/cli.rb CHANGED
@@ -25,8 +25,8 @@ module Kondate
25
25
  Config.configure(@options)
26
26
  end
27
27
 
28
- desc "init [target_dir = .]", "Initialize kondate directory tree"
29
- def init(target_dir = '.')
28
+ desc "init [target_dir]", "Initialize kondate directory tree"
29
+ def init(target_dir)
30
30
  Config.kondate_directories.each do |_, dir|
31
31
  $stdout.puts "mkdir -p #{File.join(target_dir, dir)}"
32
32
  FileUtils.mkdir_p(File.join(target_dir, dir)) unless @options[:dry_run]
@@ -84,16 +84,16 @@ module Kondate
84
84
  end
85
85
  $stdout.puts "Target hosts are [#{hosts.join(", ")}]"
86
86
 
87
- property_files_of_hosts, summarized_property_files, hosts_of_roles = build_property_files_of_hosts(hosts)
87
+ property_files_of, summarized_property_files, hosts_of = build_property_files_of(hosts)
88
88
  begin
89
- if proceed?(summarized_property_files, hosts_of_roles)
89
+ if proceed?(summarized_property_files, hosts_of)
90
90
  successes = Parallel.map(hosts, in_processes: @options[:parallel]) do |host|
91
- do_itamae(host, property_files_of_hosts[host])
91
+ do_itamae(host, property_files_of[host])
92
92
  end
93
93
  exit(-1) unless successes.all?
94
94
  end
95
95
  ensure
96
- clean_property_files_of_hosts(property_files_of_hosts)
96
+ property_files_of.values.each {|property_files| clean_property_files(property_files) }
97
97
  end
98
98
  end
99
99
 
@@ -130,23 +130,24 @@ module Kondate
130
130
  end
131
131
  $stdout.puts "Target hosts are [#{hosts.join(", ")}]"
132
132
 
133
- property_files_of_hosts, summarized_property_files, hosts_of_roles = build_property_files_of_hosts(hosts)
133
+ property_files_of, summarized_property_files, hosts_of = build_property_files_of(hosts)
134
134
  begin
135
- if proceed?(summarized_property_files, hosts_of_roles)
135
+ if proceed?(summarized_property_files, hosts_of)
136
136
  successes = Parallel.map(hosts, in_processes: @options[:parallel]) do |host|
137
- do_serverspec(host, property_files_of_hosts[host])
137
+ do_serverspec(host, property_files_of[host])
138
138
  end
139
139
  exit(-1) unless successes.all?
140
140
  end
141
141
  ensure
142
- clean_property_files_of_hosts(property_files_of_hosts)
142
+ property_files_of.values.each {|files| clean_property_files(files) }
143
143
  end
144
144
  end
145
145
 
146
146
  private
147
147
 
148
148
  def do_itamae(host, property_files)
149
- ENV['RUBYOPT'] = "-I #{Config.plugin_dir} -r bundler/setup -r ext/itamae/kondate"
149
+ env = {}
150
+ env['RUBYOPT'] = "-I #{Config.plugin_dir} -r bundler/setup -r ext/itamae/kondate"
150
151
  property_files.each do |role, property_file|
151
152
  next if property_file.nil?
152
153
  command = "bundle exec itamae ssh"
@@ -169,15 +170,16 @@ module Kondate
169
170
  command << " --profile=#{@options[:profile]}" if @options[:profile]
170
171
  command << " --recipe-graph=#{@options[:recipe_graph]}" if @options[:recipe_graph]
171
172
  command << " bootstrap.rb"
172
- $stdout.puts command
173
- return false unless system(command)
173
+ $stdout.puts "env #{env.map {|k, v| "#{k}=#{v.shellescape}" }.join(' ')} #{command}"
174
+ return false unless system(env, command)
174
175
  end
175
176
  true
176
177
  end
177
178
 
178
179
  def do_serverspec(host, property_files)
179
- ENV['RUBYOPT'] = "-I #{Config.plugin_dir} -r bundler/setup -r ext/serverspec/kondate"
180
- ENV['TARGET_VAGRANT'] = '1' if @options[:vagrant]
180
+ env = {}
181
+ env['TARGET_VAGRANT'] = '1' if @options[:vagrant]
182
+ env['RUBYOPT'] = "-I #{Config.plugin_dir} -r bundler/setup -r ext/serverspec/kondate"
181
183
  property_files.each do |role, property_file|
182
184
  next if property_file.nil?
183
185
  recipes = YAML.load_file(property_file)['attributes'].keys.map {|recipe|
@@ -186,16 +188,17 @@ module Kondate
186
188
  recipes << File.join(Config.roles_recipes_serverspec_dir, role)
187
189
  spec_files = recipes.map {|recipe| "#{recipe}_spec.rb"}.select! {|spec| File.exist?(spec) }
188
190
 
189
- command = "TARGET_HOST=#{host.shellescape} TARGET_NODE_FILE=#{property_file.shellescape} bundle exec rspec"
190
- command << " #{spec_files.map{|f| f.shellescape }.join(' ')}"
191
- $stdout.puts command
192
- return false unless system(command)
191
+ env['TARGET_HOST'] = host
192
+ env['TARGET_NODE_FILE'] = property_file
193
+ command = "bundle exec rspec #{spec_files.map{|f| f.shellescape }.join(' ')}"
194
+ $stdout.puts "env #{env.map {|k, v| "#{k}=#{v.shellescape}" }.join(' ')} #{command}"
195
+ return false unless system(env, command)
193
196
  end
194
197
  true
195
198
  end
196
199
 
197
- def proceed?(property_files, hosts_of_roles = {})
198
- print_property_files(property_files, hosts_of_roles)
200
+ def proceed?(property_files, hosts_of = {})
201
+ print_property_files(property_files, hosts_of)
199
202
  if property_files.values.compact.empty?
200
203
  $stderr.puts "Nothing to run"
201
204
  false
@@ -207,7 +210,7 @@ module Kondate
207
210
  end
208
211
  end
209
212
 
210
- def print_property_files(property_files, hosts_of_roles = {})
213
+ def print_property_files(property_files, hosts_of = {})
211
214
  roles = property_files.keys
212
215
  if roles.nil? or roles.empty?
213
216
  $stderr.puts 'No role'
@@ -216,7 +219,7 @@ module Kondate
216
219
  $stdout.puts "Show property files for roles: [#{roles.join(", ")}]"
217
220
 
218
221
  property_files.each do |role, property_file|
219
- hosts = hosts_of_roles[role]
222
+ hosts = hosts_of[role]
220
223
  if hosts.nil? # itamae
221
224
  $stdout.print "Show property file for role: #{role}"
222
225
  else # itamae_role
@@ -239,12 +242,6 @@ module Kondate
239
242
  end
240
243
  end
241
244
 
242
- def clean_property_files_of_hosts(property_files_of_hosts)
243
- property_files_of_hosts.values.each do |property_files|
244
- clean_property_files(property_files)
245
- end
246
- end
247
-
248
245
  # @return [Hash] key value pairs whoses keys are roles and values are path (or nil)
249
246
  def build_property_files(host)
250
247
  builder = PropertyBuilder.new(host)
@@ -262,17 +259,17 @@ module Kondate
262
259
  property_files
263
260
  end
264
261
 
265
- def build_property_files_of_hosts(hosts)
262
+ def build_property_files_of(hosts)
266
263
  summarized_property_files = {}
267
- property_files_of_hosts = {}
268
- hosts_of_roles = {}
264
+ property_files_of = {}
265
+ hosts_of = {}
269
266
  hosts.each do |host|
270
267
  property_files = build_property_files(host)
271
- property_files_of_hosts[host] = property_files
268
+ property_files_of[host] = property_files
272
269
  property_files.each {|role, path| summarized_property_files[role] ||= path }
273
- property_files.each {|role, path| (hosts_of_roles[role] ||= []) << host }
270
+ property_files.each {|role, path| (hosts_of[role] ||= []) << host }
274
271
  end
275
- [property_files_of_hosts, summarized_property_files, hosts_of_roles]
272
+ [property_files_of, summarized_property_files, hosts_of]
276
273
  end
277
274
 
278
275
  def mask_secrets(str)
@@ -13,12 +13,12 @@ module Kondate
13
13
  raise ConfigError.new('file: path is not configured') unless config.path
14
14
  @path = config.path
15
15
 
16
- @roles_of_hosts = YAML.load_file(@path)
17
- @hosts_of_roles = {}
18
- @roles_of_hosts.each do |host, roles|
16
+ @roles_of = YAML.load_file(@path)
17
+ @hosts_of = {}
18
+ @roles_of.each do |host, roles|
19
19
  roles.each do |role|
20
- @hosts_of_roles[role] ||= []
21
- @hosts_of_roles[role] << host
20
+ @hosts_of[role] ||= []
21
+ @hosts_of[role] << host
22
22
  end
23
23
  end
24
24
  end
@@ -32,7 +32,7 @@ module Kondate
32
32
  # @param [String] host hostname
33
33
  # @return [Array] array of roles
34
34
  def get_roles(host)
35
- @roles_of_hosts[host]
35
+ @roles_of[host]
36
36
  end
37
37
 
38
38
  # @param [String] role role
@@ -40,7 +40,7 @@ module Kondate
40
40
  #
41
41
  # Available from kondate >= 0.3.0
42
42
  def get_hosts(role)
43
- @hosts_of_roles[role]
43
+ @hosts_of[role]
44
44
  end
45
45
  end
46
46
  end
@@ -1,3 +1,3 @@
1
1
  module Kondate
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kondate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: itamae