ansible_spec 0.2.23 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +7 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/ansible_spec.gemspec +2 -1
- data/lib/ansible_spec/load_ansible.rb +106 -9
- data/lib/ansible_spec/version.rb +1 -1
- data/lib/src/spec/spec_helper.rb +5 -4
- data/spec/case/get_variable/empty_group/group_vars/group_a.yml +2 -0
- data/spec/case/get_variable/empty_group/group_vars/group_b.yml +2 -0
- data/spec/case/get_variable/empty_group/hosts +3 -0
- data/spec/case/get_variable/empty_group/site.yml +9 -0
- data/spec/case/get_variable/group_each_vars_parent_child/group_vars/all.yml +6 -0
- data/spec/case/get_variable/group_each_vars_parent_child/group_vars/group1/vars +4 -0
- data/spec/case/get_variable/group_each_vars_parent_child/group_vars/group2/vars +4 -0
- data/spec/case/get_variable/group_each_vars_parent_child/group_vars/parentgroup/vars +5 -0
- data/spec/case/get_variable/group_each_vars_parent_child/hosts +13 -0
- data/spec/case/get_variable/group_each_vars_parent_child/site.yml +6 -0
- data/spec/case/get_variable/group_each_vars_parent_child/site1.yml +6 -0
- data/spec/case/get_variable/group_each_vars_parent_child/site2.yml +6 -0
- data/spec/case/get_variable/group_each_vars_parent_child/site3.yml +6 -0
- data/spec/case/get_variable/resolve_variables/group_vars/all.yml +24 -0
- data/spec/case/get_variable/resolve_variables/hosts +5 -0
- data/spec/case/get_variable/resolve_variables/site.yml +3 -0
- data/spec/case/load_vars_file/vault_dir/ansible.cfg +2 -0
- data/spec/case/load_vars_file/vault_dir/group_vars/all/vault_file +6 -0
- data/spec/case/load_vars_file/vault_dir/vault-password-file +1 -0
- data/spec/get_variable_spec.rb +239 -25
- data/spec/load_ansible_spec.rb +303 -4
- metadata +80 -29
@@ -0,0 +1,6 @@
|
|
1
|
+
$ANSIBLE_VAULT;1.1;AES256
|
2
|
+
33623930383865383331633337653461646233633934353935376363306265636331363565306532
|
3
|
+
3935313131623364363162616335333530376134383137350a376231363430353963646535313335
|
4
|
+
36383533346433306666623162663335353035333931366162353131383539643239646637333561
|
5
|
+
3963386635663534310a323134643666343962303733616263613535623965366337393666623832
|
6
|
+
3032
|
@@ -0,0 +1 @@
|
|
1
|
+
supersecretpassword
|
data/spec/get_variable_spec.rb
CHANGED
@@ -14,11 +14,11 @@ describe "get_variablesの実行" do
|
|
14
14
|
expect(@res.instance_of?(Hash)).to be_truthy
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'exist
|
17
|
+
it 'exist three pairs in Hash' do
|
18
18
|
expect(@res.length).to eq 3
|
19
19
|
end
|
20
20
|
|
21
|
-
it '
|
21
|
+
it 'exists each pair' do
|
22
22
|
expect(@res).to include({'role_var' => 'role_var in roles default'},
|
23
23
|
{'site_var' => 'site_var in roles default'},
|
24
24
|
{'host_var'=>'host_var in roles default'},
|
@@ -41,11 +41,11 @@ describe "get_variablesの実行" do
|
|
41
41
|
expect(@res.instance_of?(Hash)).to be_truthy
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'exist
|
44
|
+
it 'exist five pairs in Hash' do
|
45
45
|
expect(@res.length).to eq 5
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
48
|
+
it 'exists each pair' do
|
49
49
|
expect(@res).to include({'role_var' => 'group all'},
|
50
50
|
{'site_var' => 'group all'},
|
51
51
|
{'host_var'=>'group all'},
|
@@ -70,11 +70,11 @@ describe "get_variablesの実行" do
|
|
70
70
|
expect(@res.instance_of?(Hash)).to be_truthy
|
71
71
|
end
|
72
72
|
|
73
|
-
it 'exist
|
73
|
+
it 'exist five pairs in Hash' do
|
74
74
|
expect(@res.length).to eq 5
|
75
75
|
end
|
76
76
|
|
77
|
-
it '
|
77
|
+
it 'exists each pair' do
|
78
78
|
expect(@res).to include({'role_var' => 'group1'},
|
79
79
|
{'site_var' => 'group1'},
|
80
80
|
{'host_var'=>'group1'},
|
@@ -99,11 +99,11 @@ describe "get_variablesの実行" do
|
|
99
99
|
expect(@res.instance_of?(Hash)).to be_truthy
|
100
100
|
end
|
101
101
|
|
102
|
-
it 'exist
|
102
|
+
it 'exist three pairs in Hash' do
|
103
103
|
expect(@res.length).to eq 3
|
104
104
|
end
|
105
105
|
|
106
|
-
it '
|
106
|
+
it 'exists each pair' do
|
107
107
|
expect(@res).to include({'role_var' => 'host role_var'}, # in host_var/192.168.1.1.yml
|
108
108
|
{'site_var' => 'host site_var'}, # in host_var/192.168.1.1.yml
|
109
109
|
{'host_var'=>'host 192.168.1.1'}, # in host_var/192.168.1.1.yml
|
@@ -126,11 +126,11 @@ describe "get_variablesの実行" do
|
|
126
126
|
expect(@res.instance_of?(Hash)).to be_truthy
|
127
127
|
end
|
128
128
|
|
129
|
-
it 'exist
|
129
|
+
it 'exist three pairs in Hash' do
|
130
130
|
expect(@res.length).to eq 3
|
131
131
|
end
|
132
132
|
|
133
|
-
it '
|
133
|
+
it 'exists each pair' do
|
134
134
|
expect(@res).to include({'role_var' => 'host role_var'}, # in host_var/192.168.1.2.yml
|
135
135
|
{'site_var' => 'host site_var'}, # in host_var/192.168.1.2.yml
|
136
136
|
{'host_var'=>'host 192.168.1.2'}, # in host_var/192.168.1.2.yml
|
@@ -153,11 +153,11 @@ describe "get_variablesの実行" do
|
|
153
153
|
expect(@res.instance_of?(Hash)).to be_truthy
|
154
154
|
end
|
155
155
|
|
156
|
-
it 'exist
|
156
|
+
it 'exist two pairs in Hash' do
|
157
157
|
expect(@res.length).to eq 2
|
158
158
|
end
|
159
159
|
|
160
|
-
it '
|
160
|
+
it 'exists each pair' do
|
161
161
|
expect(@res).to include({'role_var' => 'site'},
|
162
162
|
{'site_var' => 'site'})
|
163
163
|
end
|
@@ -178,11 +178,11 @@ describe "get_variablesの実行" do
|
|
178
178
|
expect(@res.instance_of?(Hash)).to be_truthy
|
179
179
|
end
|
180
180
|
|
181
|
-
it 'exist
|
181
|
+
it 'exist five pairs in Hash' do
|
182
182
|
expect(@res.length).to eq 5
|
183
183
|
end
|
184
184
|
|
185
|
-
it '
|
185
|
+
it 'exists each pair' do
|
186
186
|
expect(@res).to include({'role_var' => 'site'}, # site.yml
|
187
187
|
{'site_var' => 'site'}, # site.yml
|
188
188
|
{'host_var'=>'host 192.168.1.1'}, # in host_var/192.168.1.1.yml
|
@@ -207,11 +207,11 @@ describe "get_variablesの実行" do
|
|
207
207
|
expect(@res.instance_of?(Hash)).to be_truthy
|
208
208
|
end
|
209
209
|
|
210
|
-
it 'exist
|
210
|
+
it 'exist five pairs in Hash' do
|
211
211
|
expect(@res.length).to eq 5
|
212
212
|
end
|
213
213
|
|
214
|
-
it '
|
214
|
+
it 'exists each pair' do
|
215
215
|
expect(@res).to include({'role_var' => 'role'}, # in roles/test/vars/main.yml
|
216
216
|
{'site_var' => 'site'}, # site.yml
|
217
217
|
{'host_var'=>'host 192.168.1.1'}, # in host_var/192.168.1.1.yml
|
@@ -236,11 +236,11 @@ describe "get_variablesの実行" do
|
|
236
236
|
expect(@res.instance_of?(Hash)).to be_truthy
|
237
237
|
end
|
238
238
|
|
239
|
-
it '
|
239
|
+
it 'exists one pair in Hash' do
|
240
240
|
expect(@res.length).to eq 1
|
241
241
|
end
|
242
242
|
|
243
|
-
it '
|
243
|
+
it 'exists the pair' do
|
244
244
|
expect(@res).to include({'merge_var' => {
|
245
245
|
'keep'=>'role',
|
246
246
|
'override'=>'site',
|
@@ -254,6 +254,153 @@ describe "get_variablesの実行" do
|
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
|
+
context 'Correct operation : group vars for group1 hosts ' do
|
258
|
+
before do
|
259
|
+
@current_dir = Dir.pwd()
|
260
|
+
Dir.chdir('spec/case/get_variable/group_each_vars_parent_child/')
|
261
|
+
ENV["PLAYBOOK"] = 'site1.yml'
|
262
|
+
ENV["INVENTORY"] = 'hosts'
|
263
|
+
ENV["VARS_DIRS_PATH"] = ''
|
264
|
+
@res = AnsibleSpec.get_variables("192.168.1.1", 0, "group1")
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'res is hash' do
|
268
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'exist 6 pair in Hash' do
|
272
|
+
expect(@res.length).to eq 6
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'exist each pair' do
|
276
|
+
expect(@res).to include( {"role_var"=>"group1"},
|
277
|
+
{"site_var"=>"group1"},
|
278
|
+
{"host_var"=>"group1"},
|
279
|
+
{"group_var"=>"group1"},
|
280
|
+
{"group_var_parent"=>"parentgroup"},
|
281
|
+
{"group_all_var"=>"group all"}
|
282
|
+
)
|
283
|
+
end
|
284
|
+
|
285
|
+
after do
|
286
|
+
ENV.delete('PLAYBOOK')
|
287
|
+
ENV.delete('INVENTORY')
|
288
|
+
ENV.delete('VARS_DIRS_PATH')
|
289
|
+
Dir.chdir(@current_dir)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context 'Correct operation : group vars for group2 hosts ' do
|
294
|
+
before do
|
295
|
+
@current_dir = Dir.pwd()
|
296
|
+
Dir.chdir('spec/case/get_variable/group_each_vars_parent_child/')
|
297
|
+
ENV["PLAYBOOK"] = 'site2.yml'
|
298
|
+
ENV["INVENTORY"] = 'hosts'
|
299
|
+
ENV["VARS_DIRS_PATH"] = ''
|
300
|
+
@res = AnsibleSpec.get_variables("192.168.1.2", 0, "group2")
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'res is hash' do
|
304
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'exist 6 pair in Hash' do
|
308
|
+
expect(@res.length).to eq 6
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'exist each pair' do
|
312
|
+
expect(@res).to include( {"role_var"=>"group2"},
|
313
|
+
{"site_var"=>"group2"},
|
314
|
+
{"host_var"=>"group2"},
|
315
|
+
{"group_var"=>"group2"},
|
316
|
+
{"group_var_parent"=>"parentgroup"},
|
317
|
+
{"group_all_var"=>"group all"}
|
318
|
+
)
|
319
|
+
end
|
320
|
+
|
321
|
+
after do
|
322
|
+
ENV.delete('PLAYBOOK')
|
323
|
+
ENV.delete('INVENTORY')
|
324
|
+
ENV.delete('VARS_DIRS_PATH')
|
325
|
+
Dir.chdir(@current_dir)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
context 'Correct operation : group vars for parentgroup hosts ' do
|
330
|
+
before do
|
331
|
+
@current_dir = Dir.pwd()
|
332
|
+
Dir.chdir('spec/case/get_variable/group_each_vars_parent_child/')
|
333
|
+
ENV["PLAYBOOK"] = 'site3.yml'
|
334
|
+
ENV["INVENTORY"] = 'hosts'
|
335
|
+
ENV["VARS_DIRS_PATH"] = ''
|
336
|
+
@res = AnsibleSpec.get_variables("192.168.1.1", 0, "parentgroup")
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'res is hash' do
|
340
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'exist 6 pair in Hash' do
|
344
|
+
expect(@res.length).to eq 6
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'exist each pair' do
|
348
|
+
expect(@res).to include( {"role_var"=>"parentgroup"},
|
349
|
+
{"site_var"=>"parentgroup"},
|
350
|
+
{"host_var"=>"parentgroup"},
|
351
|
+
{"group_var"=>"parentgroup"},
|
352
|
+
{"group_var_parent"=>"parentgroup"},
|
353
|
+
{"group_all_var"=>"group all"}
|
354
|
+
)
|
355
|
+
end
|
356
|
+
|
357
|
+
after do
|
358
|
+
ENV.delete('PLAYBOOK')
|
359
|
+
ENV.delete('INVENTORY')
|
360
|
+
ENV.delete('VARS_DIRS_PATH')
|
361
|
+
Dir.chdir(@current_dir)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
# Fixed a problem that there is a gap between Index passed from Rakefile when empty group exists. by #135
|
366
|
+
# cat hosts
|
367
|
+
# [group_a] #no host
|
368
|
+
# [group_b]
|
369
|
+
# localhost.localdomain ansible_ssh_private_key_file=~/.ssh/id_rsa
|
370
|
+
|
371
|
+
context 'Correct operation : empty group PR #135 ' do
|
372
|
+
before do
|
373
|
+
@current_dir = Dir.pwd()
|
374
|
+
Dir.chdir('spec/case/get_variable/empty_group')
|
375
|
+
ENV["PLAYBOOK"] = 'site.yml'
|
376
|
+
ENV["INVENTORY"] = 'hosts'
|
377
|
+
ENV["VARS_DIRS_PATH"] = ''
|
378
|
+
@res = AnsibleSpec.get_variables("localhost.localdomain", 0)
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'res is hash' do
|
382
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'exist 1 pair in Hash' do
|
386
|
+
expect(@res.length).to eq 1
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'get correct variable' do
|
390
|
+
expect(@res).to eq("group_b_var" => "fuga")
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'not get incorrect variables' do
|
394
|
+
expect(@res).not_to eq("group_a_var" => "hoge")
|
395
|
+
end
|
396
|
+
|
397
|
+
after do
|
398
|
+
ENV.delete('PLAYBOOK')
|
399
|
+
ENV.delete('INVENTORY')
|
400
|
+
ENV.delete('VARS_DIRS_PATH')
|
401
|
+
Dir.chdir(@current_dir)
|
402
|
+
end
|
403
|
+
end
|
257
404
|
end
|
258
405
|
|
259
406
|
describe "get_hash_behaviourの実行" do
|
@@ -291,6 +438,43 @@ describe "get_hash_behaviourの実行" do
|
|
291
438
|
end
|
292
439
|
end
|
293
440
|
|
441
|
+
context 'Correct operation : resolve variables' do
|
442
|
+
before do
|
443
|
+
@current_dir = Dir.pwd()
|
444
|
+
Dir.chdir('spec/case/get_variable/resolve_variables/')
|
445
|
+
@res = AnsibleSpec.get_variables('192.168.1.1', 0)
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'res is hash' do
|
449
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'exist fourteen pairs in Hash' do
|
453
|
+
expect(@res.length).to eq 14
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'exist all pairs' do
|
457
|
+
expect(@res).to include({'var_nested_one_1' => 'val_nested_one'})
|
458
|
+
expect(@res).to include({'var_nested_one_2' => 'val_nested_one'})
|
459
|
+
expect(@res).to include({'var_nested_two_1' => 'val_nested_two'})
|
460
|
+
expect(@res).to include({'var_nested_two_2' => 'val_nested_two'})
|
461
|
+
expect(@res).to include({'var_nested_two_3' => 'val_nested_two'})
|
462
|
+
expect(@res).to include({'var_nested_hash_1' => 'val_hash'})
|
463
|
+
expect(@res).to include({'var_nested_hash_2' => {'key' => 'val_hash'}})
|
464
|
+
expect(@res).to include({'var_nested_array_1' => 'val_array'})
|
465
|
+
expect(@res).to include({'var_nested_array_2' => ['val_array']})
|
466
|
+
expect(@res).to include({'var_nested_array_hash_1' => 'val_array_hash'})
|
467
|
+
expect(@res).to include({'var_nested_array_hash_2' => [{'key' => 'val_array_hash'}]})
|
468
|
+
expect(@res).to include({'var_nested_whitespace_1' => 'val_nested_whitespace'})
|
469
|
+
expect(@res).to include({'var_nested_whitespace_2' => 'val_nested_whitespace'})
|
470
|
+
expect(@res).to include({'var_missingtarget_2' => '{{ var_missingtarget_1 }}'})
|
471
|
+
end
|
472
|
+
|
473
|
+
after do
|
474
|
+
Dir.chdir(@current_dir)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
294
478
|
context 'Correct operation : mistake word in ENV["HASH_BEHAVIOUR"]' do
|
295
479
|
before do
|
296
480
|
ENV["HASH_BEHAVIOUR"] = 'mistake_word'
|
@@ -390,7 +574,7 @@ describe 'merge_variablesの実行' do
|
|
390
574
|
expect(@res.instance_of?(Hash)).to be_truthy
|
391
575
|
end
|
392
576
|
|
393
|
-
it '
|
577
|
+
it 'exists one pair in Hash' do
|
394
578
|
expect(@res.length).to eq 1
|
395
579
|
end
|
396
580
|
|
@@ -425,11 +609,11 @@ describe "load_vars_fileの実行" do
|
|
425
609
|
expect(@res.instance_of?(Hash)).to be_truthy
|
426
610
|
end
|
427
611
|
|
428
|
-
it 'exist
|
612
|
+
it 'exist one pair in Hash' do
|
429
613
|
expect(@res.length).to eq 1
|
430
614
|
end
|
431
615
|
|
432
|
-
it '
|
616
|
+
it 'exists the pair' do
|
433
617
|
expect(@res).to include({'role_var' => 'without .yml extension'})
|
434
618
|
end
|
435
619
|
|
@@ -453,11 +637,11 @@ describe "load_vars_fileの実行" do
|
|
453
637
|
expect(@res.instance_of?(Hash)).to be_truthy
|
454
638
|
end
|
455
639
|
|
456
|
-
it '
|
640
|
+
it 'exists one pair in Hash' do
|
457
641
|
expect(@res.length).to eq 1
|
458
642
|
end
|
459
643
|
|
460
|
-
it '
|
644
|
+
it 'exists the pair' do
|
461
645
|
expect(@res).to include({'role_var' => 'without .yml extension'})
|
462
646
|
end
|
463
647
|
|
@@ -479,11 +663,11 @@ describe "load_vars_fileの実行" do
|
|
479
663
|
expect(@res.instance_of?(Hash)).to be_truthy
|
480
664
|
end
|
481
665
|
|
482
|
-
it 'exist
|
666
|
+
it 'exist two pairs in Hash' do
|
483
667
|
expect(@res.length).to eq 2
|
484
668
|
end
|
485
669
|
|
486
|
-
it '
|
670
|
+
it 'exists each pair' do
|
487
671
|
expect(@res).to include({'var1' => 'val1'})
|
488
672
|
expect(@res).to include({'var2' => 'val2'})
|
489
673
|
end
|
@@ -492,4 +676,34 @@ describe "load_vars_fileの実行" do
|
|
492
676
|
Dir.chdir(@current_dir)
|
493
677
|
end
|
494
678
|
end
|
679
|
+
|
680
|
+
# Ansible::Vault support Ruby 2.1.0 and higher.
|
681
|
+
# Skip test when Ruby 1.9.3 & 2.0.0
|
682
|
+
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
|
683
|
+
context 'Correct operation : vaults in directory' do
|
684
|
+
before do
|
685
|
+
@current_dir = Dir.pwd()
|
686
|
+
Dir.chdir('spec/case/load_vars_file/vault_dir/')
|
687
|
+
vars = Hash.new
|
688
|
+
file = 'group_vars/all'
|
689
|
+
@res = AnsibleSpec.load_vars_file(vars, file)
|
690
|
+
end
|
691
|
+
|
692
|
+
it 'res is hash' do
|
693
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
694
|
+
end
|
695
|
+
|
696
|
+
it 'exists one pair in Hash' do
|
697
|
+
expect(@res.length).to eq 1
|
698
|
+
end
|
699
|
+
|
700
|
+
it 'exists the pair' do
|
701
|
+
expect(@res).to include({'vault_var' => 'val'})
|
702
|
+
end
|
703
|
+
|
704
|
+
after do
|
705
|
+
Dir.chdir(@current_dir)
|
706
|
+
end
|
707
|
+
end
|
708
|
+
end
|
495
709
|
end
|
data/spec/load_ansible_spec.rb
CHANGED
@@ -400,6 +400,229 @@ EOF
|
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
403
|
+
context 'load_targets:Test invalid return_type' do
|
404
|
+
tmp_hosts = 'hosts'
|
405
|
+
content_excpetion_msg = "Variable return_type must be value 'groups' or 'groups_parent_child_relationships'"
|
406
|
+
before do
|
407
|
+
content_h = <<'EOF'
|
408
|
+
[server]
|
409
|
+
192.168.0.103
|
410
|
+
192.168.0.104 ansible_ssh_port=22
|
411
|
+
|
412
|
+
[databases]
|
413
|
+
192.168.0.105
|
414
|
+
192.168.0.106 ansible_ssh_port=5555
|
415
|
+
|
416
|
+
[pg:children]
|
417
|
+
server
|
418
|
+
databases
|
419
|
+
EOF
|
420
|
+
create_file(tmp_hosts,content_h)
|
421
|
+
begin
|
422
|
+
@res = AnsibleSpec.load_targets(tmp_hosts, return_type='some_invalid_option')
|
423
|
+
rescue ArgumentError => e
|
424
|
+
@res = e.message
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
it 'res is string' do
|
429
|
+
expect(@res.instance_of?(String)).to be_truthy
|
430
|
+
end
|
431
|
+
|
432
|
+
it 'exist 1 string' do
|
433
|
+
expect(@res.length).to eq content_excpetion_msg.length
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'exist string' do
|
437
|
+
expect(@res).to include(content_excpetion_msg)
|
438
|
+
end
|
439
|
+
|
440
|
+
after do
|
441
|
+
File.delete(tmp_hosts)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context 'load_targets:Return groups; default return_type (="groups")' do
|
446
|
+
tmp_hosts = 'hosts'
|
447
|
+
before do
|
448
|
+
content_h = <<'EOF'
|
449
|
+
[server]
|
450
|
+
192.168.0.103
|
451
|
+
192.168.0.104 ansible_ssh_port=22
|
452
|
+
|
453
|
+
[databases]
|
454
|
+
192.168.0.105
|
455
|
+
192.168.0.106 ansible_ssh_port=5555
|
456
|
+
|
457
|
+
[pg:children]
|
458
|
+
server
|
459
|
+
databases
|
460
|
+
EOF
|
461
|
+
create_file(tmp_hosts,content_h)
|
462
|
+
@res = AnsibleSpec.load_targets(tmp_hosts)
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'res is hash' do
|
466
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
467
|
+
end
|
468
|
+
|
469
|
+
it 'exist 1 group' do
|
470
|
+
expect(@res.length).to eq 3
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'exist group' do
|
474
|
+
expect(@res.key?('server')).to be_truthy
|
475
|
+
expect(@res.key?('databases')).to be_truthy
|
476
|
+
expect(@res.key?('pg')).to be_truthy
|
477
|
+
expect(@res.key?('pg:children')).not_to be_truthy
|
478
|
+
end
|
479
|
+
|
480
|
+
it 'pg 192.168.0.103' do
|
481
|
+
obj = @res['pg'][0]
|
482
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
483
|
+
expect(obj).to include({'name' => '192.168.0.103',
|
484
|
+
'uri' => '192.168.0.103',
|
485
|
+
'port' => 22})
|
486
|
+
end
|
487
|
+
|
488
|
+
it 'pg 192.168.0.104 ansible_ssh_port=22' do
|
489
|
+
obj = @res['pg'][1]
|
490
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
491
|
+
expect(obj['name']).to eq '192.168.0.104 ansible_ssh_port=22'
|
492
|
+
expect(obj['uri']).to eq '192.168.0.104'
|
493
|
+
expect(obj['port']).to eq 22
|
494
|
+
end
|
495
|
+
|
496
|
+
it 'pg 192.168.0.105' do
|
497
|
+
obj = @res['pg'][2]
|
498
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
499
|
+
expect(obj).to include({'name' => '192.168.0.105',
|
500
|
+
'uri' => '192.168.0.105',
|
501
|
+
'port' => 22})
|
502
|
+
end
|
503
|
+
|
504
|
+
it 'pg 192.168.0.106 ansible_ssh_port=5555' do
|
505
|
+
obj = @res['pg'][3]
|
506
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
507
|
+
expect(obj['name']).to eq '192.168.0.106 ansible_ssh_port=5555'
|
508
|
+
expect(obj['uri']).to eq '192.168.0.106'
|
509
|
+
expect(obj['port']).to eq 5555
|
510
|
+
end
|
511
|
+
|
512
|
+
after do
|
513
|
+
File.delete(tmp_hosts)
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
context 'load_targets:Return groups; return_type="groups"' do
|
518
|
+
tmp_hosts = 'hosts'
|
519
|
+
before do
|
520
|
+
content_h = <<'EOF'
|
521
|
+
[server]
|
522
|
+
192.168.0.103
|
523
|
+
192.168.0.104 ansible_ssh_port=22
|
524
|
+
|
525
|
+
[databases]
|
526
|
+
192.168.0.105
|
527
|
+
192.168.0.106 ansible_ssh_port=5555
|
528
|
+
|
529
|
+
[pg:children]
|
530
|
+
server
|
531
|
+
databases
|
532
|
+
EOF
|
533
|
+
create_file(tmp_hosts,content_h)
|
534
|
+
@res = AnsibleSpec.load_targets(tmp_hosts, return_type='groups')
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'res is hash' do
|
538
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
539
|
+
end
|
540
|
+
|
541
|
+
it 'exist 1 group' do
|
542
|
+
expect(@res.length).to eq 3
|
543
|
+
end
|
544
|
+
|
545
|
+
it 'exist group' do
|
546
|
+
expect(@res.key?('server')).to be_truthy
|
547
|
+
expect(@res.key?('databases')).to be_truthy
|
548
|
+
expect(@res.key?('pg')).to be_truthy
|
549
|
+
expect(@res.key?('pg:children')).not_to be_truthy
|
550
|
+
end
|
551
|
+
|
552
|
+
it 'pg 192.168.0.103' do
|
553
|
+
obj = @res['pg'][0]
|
554
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
555
|
+
expect(obj).to include({'name' => '192.168.0.103',
|
556
|
+
'uri' => '192.168.0.103',
|
557
|
+
'port' => 22})
|
558
|
+
end
|
559
|
+
|
560
|
+
it 'pg 192.168.0.104 ansible_ssh_port=22' do
|
561
|
+
obj = @res['pg'][1]
|
562
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
563
|
+
expect(obj['name']).to eq '192.168.0.104 ansible_ssh_port=22'
|
564
|
+
expect(obj['uri']).to eq '192.168.0.104'
|
565
|
+
expect(obj['port']).to eq 22
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'pg 192.168.0.105' do
|
569
|
+
obj = @res['pg'][2]
|
570
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
571
|
+
expect(obj).to include({'name' => '192.168.0.105',
|
572
|
+
'uri' => '192.168.0.105',
|
573
|
+
'port' => 22})
|
574
|
+
end
|
575
|
+
|
576
|
+
it 'pg 192.168.0.106 ansible_ssh_port=5555' do
|
577
|
+
obj = @res['pg'][3]
|
578
|
+
expect(obj.instance_of?(Hash)).to be_truthy
|
579
|
+
expect(obj['name']).to eq '192.168.0.106 ansible_ssh_port=5555'
|
580
|
+
expect(obj['uri']).to eq '192.168.0.106'
|
581
|
+
expect(obj['port']).to eq 5555
|
582
|
+
end
|
583
|
+
|
584
|
+
after do
|
585
|
+
File.delete(tmp_hosts)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
context 'load_targets:Return groups parent child relationships; return_type="groups_parent_child_relationships"' do
|
590
|
+
tmp_hosts = 'hosts'
|
591
|
+
before do
|
592
|
+
content_h = <<'EOF'
|
593
|
+
[server]
|
594
|
+
192.168.0.103
|
595
|
+
192.168.0.104 ansible_ssh_port=22
|
596
|
+
|
597
|
+
[databases]
|
598
|
+
192.168.0.105
|
599
|
+
192.168.0.106 ansible_ssh_port=5555
|
600
|
+
|
601
|
+
[pg:children]
|
602
|
+
server
|
603
|
+
databases
|
604
|
+
EOF
|
605
|
+
create_file(tmp_hosts,content_h)
|
606
|
+
@res = AnsibleSpec.load_targets(tmp_hosts, return_type='groups_parent_child_relationships')
|
607
|
+
end
|
608
|
+
|
609
|
+
it 'res is hash' do
|
610
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
611
|
+
end
|
612
|
+
|
613
|
+
it 'exist 1 group parent child relationship in Hash' do
|
614
|
+
expect(@res.length).to eq 1
|
615
|
+
end
|
616
|
+
|
617
|
+
it 'exist each pair' do
|
618
|
+
expect(@res).to include({"pg"=>["server", "databases"]})
|
619
|
+
end
|
620
|
+
|
621
|
+
after do
|
622
|
+
File.delete(tmp_hosts)
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
403
626
|
end
|
404
627
|
|
405
628
|
describe "load_playbookの実行" do
|
@@ -1308,16 +1531,20 @@ EOF
|
|
1308
1531
|
expect(@res[0]['hosts'].instance_of?(Array)).to be_truthy
|
1309
1532
|
expect([{'name' => '192.168.0.103',
|
1310
1533
|
'uri' => '192.168.0.103',
|
1311
|
-
'port' => 22
|
1534
|
+
'port' => 22,
|
1535
|
+
'connection' => 'ssh'},
|
1312
1536
|
{'name' => '192.168.0.104',
|
1313
1537
|
'uri' => '192.168.0.104',
|
1314
|
-
'port' => 22
|
1538
|
+
'port' => 22,
|
1539
|
+
'connection' => 'ssh'},
|
1315
1540
|
{'name' => '192.168.0.105',
|
1316
1541
|
'uri' => '192.168.0.105',
|
1317
|
-
'port' => 22
|
1542
|
+
'port' => 22,
|
1543
|
+
'connection' => 'ssh'},
|
1318
1544
|
{'name' => '192.168.0.106',
|
1319
1545
|
'uri' => '192.168.0.106',
|
1320
|
-
'port' => 22
|
1546
|
+
'port' => 22,
|
1547
|
+
'connection' => 'ssh'}]).to match_array(@res[0]['hosts'])
|
1321
1548
|
end
|
1322
1549
|
|
1323
1550
|
it 'exist user' do
|
@@ -1453,18 +1680,22 @@ EOF
|
|
1453
1680
|
expect([{'name' => '192.168.0.103',
|
1454
1681
|
'uri' => '192.168.0.103',
|
1455
1682
|
'port' => 22,
|
1683
|
+
'connection' => 'ssh',
|
1456
1684
|
'hosts'=>'server'},
|
1457
1685
|
{'name' => '192.168.0.104',
|
1458
1686
|
'uri' => '192.168.0.104',
|
1459
1687
|
'port' => 22,
|
1688
|
+
'connection' => 'ssh',
|
1460
1689
|
'hosts'=>'server'},
|
1461
1690
|
{'name' => '192.168.0.105',
|
1462
1691
|
'uri' => '192.168.0.105',
|
1463
1692
|
'port' => 22,
|
1693
|
+
'connection' => 'ssh',
|
1464
1694
|
'hosts'=>'server2'},
|
1465
1695
|
{'name' => '192.168.0.106',
|
1466
1696
|
'uri' => '192.168.0.106',
|
1467
1697
|
'port' => 22,
|
1698
|
+
'connection' => 'ssh',
|
1468
1699
|
'hosts'=>'server2'}]).to match_array(@res[0]['hosts'])
|
1469
1700
|
end
|
1470
1701
|
|
@@ -1570,4 +1801,72 @@ EOF
|
|
1570
1801
|
File.delete(tmp_hosts)
|
1571
1802
|
end
|
1572
1803
|
end
|
1804
|
+
|
1805
|
+
context 'Issue 126 Array Error' do
|
1806
|
+
require 'yaml'
|
1807
|
+
tmp_ansiblespec = '.ansiblespec'
|
1808
|
+
tmp_playbook = 'site.yml'
|
1809
|
+
tmp_hosts = 'hosts'
|
1810
|
+
|
1811
|
+
before do
|
1812
|
+
|
1813
|
+
content = <<'EOF'
|
1814
|
+
---
|
1815
|
+
-
|
1816
|
+
playbook: site.yml
|
1817
|
+
inventory: hosts
|
1818
|
+
EOF
|
1819
|
+
|
1820
|
+
content_p = <<'EOF'
|
1821
|
+
- name: Ansible-Sample-TDD-1
|
1822
|
+
hosts:
|
1823
|
+
- server
|
1824
|
+
user: root
|
1825
|
+
roles:
|
1826
|
+
- role: nginx
|
1827
|
+
EOF
|
1828
|
+
|
1829
|
+
content_h = <<'EOF'
|
1830
|
+
[server]
|
1831
|
+
host1
|
1832
|
+
host2
|
1833
|
+
host3
|
1834
|
+
host4
|
1835
|
+
host5
|
1836
|
+
EOF
|
1837
|
+
|
1838
|
+
create_file(tmp_ansiblespec,content)
|
1839
|
+
create_file(tmp_playbook,content_p)
|
1840
|
+
create_file(tmp_hosts,content_h)
|
1841
|
+
@res = AnsibleSpec.get_properties
|
1842
|
+
end
|
1843
|
+
|
1844
|
+
it 'check 5 hosts' do
|
1845
|
+
expect(@res[0]["hosts"].length).to eq 5
|
1846
|
+
end
|
1847
|
+
|
1848
|
+
it 'check host1' do
|
1849
|
+
expect(@res[0]["hosts"][0]["name"]).to eq "host1"
|
1850
|
+
end
|
1851
|
+
|
1852
|
+
it 'check host2' do
|
1853
|
+
expect(@res[0]["hosts"][1]["name"]).to eq "host2" #not " host2"
|
1854
|
+
end
|
1855
|
+
it 'check host3' do
|
1856
|
+
expect(@res[0]["hosts"][2]["name"]).to eq "host3" #not "host3\t"
|
1857
|
+
end
|
1858
|
+
it 'check host4' do
|
1859
|
+
expect(@res[0]["hosts"][3]["name"]).to eq "host4" #not "\thost4"
|
1860
|
+
end
|
1861
|
+
|
1862
|
+
it 'check host5' do
|
1863
|
+
expect(@res[0]["hosts"][4]["name"]).to eq "host5" #not "\thost5\t"
|
1864
|
+
end
|
1865
|
+
|
1866
|
+
after do
|
1867
|
+
File.delete(tmp_ansiblespec)
|
1868
|
+
File.delete(tmp_playbook)
|
1869
|
+
File.delete(tmp_hosts)
|
1870
|
+
end
|
1871
|
+
end
|
1573
1872
|
end
|