ansible_spec 0.2.9 → 0.2.10

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: d457c5cbf7de2872b6567b14f4743c967a05f9f3
4
- data.tar.gz: 9a4af4588ffd83f2249fbba3ee13f69f250ad012
3
+ metadata.gz: 39b483b0e6e4712c41e9785d82a8a7f04c0bdaea
4
+ data.tar.gz: c4f559f6ffa278fc2c50f553fff48af455cd6431
5
5
  SHA512:
6
- metadata.gz: 2351376f83753be73282de06c2af2f2b7a821cc221fbc86a3b9f29fbf5b571dfe75b8f8a0e6a0d3cc8fe82439bfff0936b4ded73e3d9f95eb8450206b6267225
7
- data.tar.gz: 5162d04115f849d6b9a04431eccfbc837ea16d5fbf3ea8b572f045105fd0bf9c90d312735f65eb50eb30085fe5d0f59389b349411767429c924dda859db29b34
6
+ metadata.gz: d4d2724571d72783076e2ce0f27cdd4f9516720015cb2977f796353e92ac7aae9e93e40e62c7a2e6929c456a1b284e1544e1d088ffd642161df6dcbbfa3ef499
7
+ data.tar.gz: 0807543a869a4bfe97ef9ed716f223840975c419f76d964dda4eacc88d4d533061b97b614bf44f1d51b2f24a1184c40ffe4535c83cb6917d4480a06f36932e0b
@@ -1,3 +1,6 @@
1
+ # v0.2.10
2
+ - Merge [support group and host variables without yml extention.](https://github.com/volanja/ansible_spec/pull/66) by [okamototk](https://github.com/okamototk)
3
+
1
4
  # v0.2.9
2
5
  - Merge [#65 return an empty array when the group has no hosts in it](https://github.com/volanja/ansible_spec/pull/65) by [franmrl](https://github.com/franmrl)
3
6
 
@@ -268,6 +268,27 @@ module AnsibleSpec
268
268
  end
269
269
  end
270
270
 
271
+ # param: hash
272
+ # param: variable file
273
+ def self.load_vars_file(vars, path)
274
+ vars_file = path
275
+ if File.exist?(vars_file)
276
+ yaml = YAML.load_file(vars_file)
277
+ if yaml.kind_of?(Hash)
278
+ vars.merge!(yaml)
279
+ end
280
+ else
281
+ vars_file = path+".yml"
282
+ if File.exist?(vars_file)
283
+ yaml = YAML.load_file(vars_file)
284
+ if yaml.kind_of?(Hash)
285
+ vars.merge!(yaml)
286
+ end
287
+ end
288
+ end
289
+ return vars
290
+ end
291
+
271
292
  # return: json
272
293
  # {"name"=>"Ansible-Sample-TDD", "hosts"=>["192.168.0.103"], "user"=>"root", "roles"=>["nginx", "mariadb"]}
273
294
  def self.get_properties()
@@ -306,33 +327,15 @@ module AnsibleSpec
306
327
  end
307
328
 
308
329
  # all group
309
- vars_file = 'group_vars/all.yml'
310
- if File.exist?(vars_file)
311
- yaml = YAML.load_file(vars_file)
312
- if yaml.kind_of?(Hash)
313
- vars.merge!(yaml)
314
- end
315
- end
330
+ vars = load_vars_file(vars ,'group_vars/all')
316
331
 
317
332
  # each group vars
318
333
  if p[group_idx].has_key?('group')
319
- vars_file = "group_vars/#{p[group_idx]['group']}.yml"
320
- if File.exist?(vars_file)
321
- yaml = YAML.load_file(vars_file)
322
- if yaml.kind_of?(Hash)
323
- vars.merge!(yaml)
324
- end
325
- end
334
+ vars = load_vars_file(vars ,"group_vars/#{p[group_idx]['group']}")
326
335
  end
327
336
 
328
337
  # each host vars
329
- vars_file = "host_vars/#{host}.yml"
330
- if File.exist?(vars_file)
331
- yaml = YAML.load_file(vars_file)
332
- if yaml.kind_of?(Hash)
333
- vars.merge!(yaml)
334
- end
335
- end
338
+ vars = load_vars_file(vars ,"host_vars/#{host}")
336
339
 
337
340
  # site vars
338
341
  if p[group_idx].has_key?('vars')
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ role_var: "without .yml extension"
@@ -0,0 +1,6 @@
1
+ ---
2
+ role_var: "group all"
3
+ site_var: "group all"
4
+ host_var: "group all"
5
+ group_var: "group all"
6
+ group_all_var: "group all"
@@ -225,3 +225,33 @@ describe "get_variablesの実行" do
225
225
  end
226
226
  end
227
227
  end
228
+
229
+ describe "load_vars_fileの実行" do
230
+ context 'Correct operation : without .yml extension' do
231
+ # https://github.com/volanja/ansible_spec/pull/66
232
+ # group_vars/xxx priority is higher than group_vars/xxx.yml.
233
+ before do
234
+ @current_dir = Dir.pwd()
235
+ Dir.chdir('spec/case/load_vars_file/group_all/')
236
+ vars = Hash.new
237
+ file = 'group_vars/all'
238
+ @res = AnsibleSpec.load_vars_file(vars, file)
239
+ end
240
+
241
+ it 'res is hash' do
242
+ expect(@res.instance_of?(Hash)).to be_truthy
243
+ end
244
+
245
+ it 'exist 1 pair in Hash' do
246
+ expect(@res.length).to eq 1
247
+ end
248
+
249
+ it 'exist each pair' do
250
+ expect(@res).to include({'role_var' => 'without .yml extension'})
251
+ end
252
+
253
+ after do
254
+ Dir.chdir(@current_dir)
255
+ end
256
+ end
257
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-27 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -163,6 +163,8 @@ files:
163
163
  - spec/case/get_variable/roles_default/hosts
164
164
  - spec/case/get_variable/roles_default/roles/test/defaults/main.yml
165
165
  - spec/case/get_variable/roles_default/site.yml
166
+ - spec/case/load_vars_file/group_all/group_vars/all
167
+ - spec/case/load_vars_file/group_all/group_vars/all.yml
166
168
  - spec/commands_spec.rb
167
169
  - spec/dependency_spec.rb
168
170
  - spec/dynamic_inventory_spec.rb
@@ -228,6 +230,8 @@ test_files:
228
230
  - spec/case/get_variable/roles_default/hosts
229
231
  - spec/case/get_variable/roles_default/roles/test/defaults/main.yml
230
232
  - spec/case/get_variable/roles_default/site.yml
233
+ - spec/case/load_vars_file/group_all/group_vars/all
234
+ - spec/case/load_vars_file/group_all/group_vars/all.yml
231
235
  - spec/commands_spec.rb
232
236
  - spec/dependency_spec.rb
233
237
  - spec/dynamic_inventory_spec.rb