ansible_spec 0.2.23 → 0.2.24

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
- SHA1:
3
- metadata.gz: ea92ad1db5c6331ab0f51cb0cc9f8357d6fad5a1
4
- data.tar.gz: 3529e094be9910fb8acb9c1e3df7661e4e21135e
2
+ SHA256:
3
+ metadata.gz: '0866b7bafc7f4af084f4e132e9c3238e7618e7568b1c029fe8997cf4c511c86f'
4
+ data.tar.gz: 81e964b2f1751f33eb8f6805c953488b4a965d1bc3e20f4577e4b6feb2fe7dc6
5
5
  SHA512:
6
- metadata.gz: 4f8121627c3ffb1b2011e8b77d2ef0704b8f64ab59075c2973e7768c7fb26a1c21606332acdb7a6faedc1d4d17be4287abf354de010fc4c72ded2d7db003aa88
7
- data.tar.gz: ded735c540319da5a2443d9639390f3e0a5d915a5249e410d0295f3f32b99b09bcc6625384d2778784bf8f7484f4f199a6a5c52b6dce9eb2f0a6149927f59d3b
6
+ metadata.gz: c349056c633eafd1f5835e362a326ca9fef0a52e482939828081df43ab7227a8cebedcf750963984d79df67c7ccc88349afc4ac67b517df2a209c67a3225d509
7
+ data.tar.gz: ee0722a55e92a7c0109553ad198ae2b0aefaf3f78e3a754137f95b55873060498ff0ec7a420732520c51c740be72108aa6c65b7d47ac96ecc17b5d490e93c9b4
@@ -4,9 +4,9 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.10
7
- - 2.2.9
8
- - 2.3.6
9
- - 2.4.3
10
- - 2.5.0
7
+ - 2.2.10
8
+ - 2.3.7
9
+ - 2.4.4
10
+ - 2.5.1
11
11
  script:
12
12
  - rspec spec
@@ -1,3 +1,6 @@
1
+ # v0.2.24
2
+ - Merge [#117 Feature resolve variables](https://github.com/volanja/ansible_spec/pull/117) by [RebelCodeBase](https://github.com/RebelCodeBase)
3
+
1
4
  # v0.2.23
2
5
  - Merge [#115 Support import_playbook](https://github.com/volanja/ansible_spec/pull/115) by [seiji](https://github.com/seiji)
3
6
  - Merge [#113 Make ENV variables override SSH config file options](https://github.com/volanja/ansible_spec/pull/113) by [Jonnymcc](https://github.com/Jonnymcc)
@@ -347,7 +347,7 @@ module AnsibleSpec
347
347
  if File.directory?(vars_file)
348
348
  Dir.glob(File.join(vars_file, '*')).each { |f|
349
349
  vars = load_vars_file(vars, f)
350
- }
350
+ }
351
351
  else
352
352
  yaml = YAML.load_file(vars_file)
353
353
  vars = merge_variables(vars, yaml)
@@ -431,6 +431,43 @@ module AnsibleSpec
431
431
  target_host.keys[0]
432
432
  end
433
433
 
434
+ # query replace jinja2 templates with target values
435
+ # param: hash (cf. result self.get_variables)
436
+ # param: number of iterations if found_template
437
+ # return: hash
438
+ def self.resolve_variables(vars, max_level=100)
439
+ vars_yaml = vars.to_yaml
440
+ level = 0
441
+ begin
442
+ found_template = false
443
+ level += 1
444
+
445
+ # query replace jinja2 templates in yaml
446
+ # replace in-place (gsub!)
447
+ # use non-greedy regex (.*?)
448
+ vars_yaml.gsub!(/{{.*?}}/) do |template|
449
+
450
+ # grab target variable
451
+ # ignore whitespaces (\s*)
452
+ # use non-greedy regex (.*?)
453
+ target = template.gsub(/{{\s*(.*?)\s*}}/, '\1')
454
+
455
+ # lookup value of target variable
456
+ value = vars[target]
457
+
458
+ # return lookup value if it exists
459
+ # or leave template alone
460
+ if value.nil?
461
+ template
462
+ else
463
+ found_template = true
464
+ value
465
+ end
466
+ end
467
+ end while found_template and level <= max_level
468
+ return YAML.load(vars_yaml)
469
+ end
470
+
434
471
  def self.get_variables(host, group_idx, hosts=nil)
435
472
  vars = {}
436
473
  p = self.get_properties
@@ -479,7 +516,7 @@ module AnsibleSpec
479
516
  end
480
517
  end
481
518
 
482
- return vars
519
+ return resolve_variables(vars)
483
520
 
484
521
  end
485
522
 
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.2.23"
2
+ VERSION = "0.2.24"
3
3
  end
@@ -0,0 +1,24 @@
1
+ ---
2
+ var_nested_one_1: 'val_nested_one'
3
+ var_nested_one_2: "{{ var_nested_one_1 }}"
4
+
5
+ var_nested_two_1: 'val_nested_two'
6
+ var_nested_two_2: "{{ var_nested_two_1 }}"
7
+ var_nested_two_3: "{{ var_nested_two_2 }}"
8
+
9
+ var_nested_hash_1: 'val_hash'
10
+ var_nested_hash_2:
11
+ key: "{{ var_nested_hash_1 }}"
12
+
13
+ var_nested_array_1: 'val_array'
14
+ var_nested_array_2:
15
+ - "{{ var_nested_array_1 }}"
16
+
17
+ var_nested_array_hash_1: 'val_array_hash'
18
+ var_nested_array_hash_2:
19
+ - key: "{{ var_nested_array_hash_1 }}"
20
+
21
+ var_nested_whitespace_1: val_nested_whitespace
22
+ var_nested_whitespace_2: "{{var_nested_whitespace_1 }}"
23
+
24
+ var_missingtarget_2: "{{ var_missingtarget_1 }}"
@@ -0,0 +1,5 @@
1
+ [resolve]
2
+ 192.168.1.1
3
+
4
+
5
+
@@ -0,0 +1,3 @@
1
+ - name: resolve
2
+ hosts: resolve
3
+ connection: local
@@ -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 3 pair in Hash' do
17
+ it 'exist three pairs in Hash' do
18
18
  expect(@res.length).to eq 3
19
19
  end
20
20
 
21
- it 'exist each pair' do
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 5 pair in Hash' do
44
+ it 'exist five pairs in Hash' do
45
45
  expect(@res.length).to eq 5
46
46
  end
47
47
 
48
- it 'exist each pair' do
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 5 pair in Hash' do
73
+ it 'exist five pairs in Hash' do
74
74
  expect(@res.length).to eq 5
75
75
  end
76
76
 
77
- it 'exist each pair' do
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 3 pair in Hash' do
102
+ it 'exist three pairs in Hash' do
103
103
  expect(@res.length).to eq 3
104
104
  end
105
105
 
106
- it 'exist each pair' do
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 3 pair in Hash' do
129
+ it 'exist three pairs in Hash' do
130
130
  expect(@res.length).to eq 3
131
131
  end
132
132
 
133
- it 'exist each pair' do
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 2 pair in Hash' do
156
+ it 'exist two pairs in Hash' do
157
157
  expect(@res.length).to eq 2
158
158
  end
159
159
 
160
- it 'exist each pair' do
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 5 pair in Hash' do
181
+ it 'exist five pairs in Hash' do
182
182
  expect(@res.length).to eq 5
183
183
  end
184
184
 
185
- it 'exist each pair' do
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 5 pair in Hash' do
210
+ it 'exist five pairs in Hash' do
211
211
  expect(@res.length).to eq 5
212
212
  end
213
213
 
214
- it 'exist each pair' do
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 'exist 1 pair in Hash' do
239
+ it 'exists one pair in Hash' do
240
240
  expect(@res.length).to eq 1
241
241
  end
242
242
 
243
- it 'exist each pair' do
243
+ it 'exists the pair' do
244
244
  expect(@res).to include({'merge_var' => {
245
245
  'keep'=>'role',
246
246
  'override'=>'site',
@@ -291,6 +291,43 @@ describe "get_hash_behaviourの実行" do
291
291
  end
292
292
  end
293
293
 
294
+ context 'Correct operation : resolve variables' do
295
+ before do
296
+ @current_dir = Dir.pwd()
297
+ Dir.chdir('spec/case/get_variable/resolve_variables/')
298
+ @res = AnsibleSpec.get_variables('192.168.1.1', 0)
299
+ end
300
+
301
+ it 'res is hash' do
302
+ expect(@res.instance_of?(Hash)).to be_truthy
303
+ end
304
+
305
+ it 'exist fourteen pairs in Hash' do
306
+ expect(@res.length).to eq 14
307
+ end
308
+
309
+ it 'exist all pairs' do
310
+ expect(@res).to include({'var_nested_one_1' => 'val_nested_one'})
311
+ expect(@res).to include({'var_nested_one_2' => 'val_nested_one'})
312
+ expect(@res).to include({'var_nested_two_1' => 'val_nested_two'})
313
+ expect(@res).to include({'var_nested_two_2' => 'val_nested_two'})
314
+ expect(@res).to include({'var_nested_two_3' => 'val_nested_two'})
315
+ expect(@res).to include({'var_nested_hash_1' => 'val_hash'})
316
+ expect(@res).to include({'var_nested_hash_2' => {'key' => 'val_hash'}})
317
+ expect(@res).to include({'var_nested_array_1' => 'val_array'})
318
+ expect(@res).to include({'var_nested_array_2' => ['val_array']})
319
+ expect(@res).to include({'var_nested_array_hash_1' => 'val_array_hash'})
320
+ expect(@res).to include({'var_nested_array_hash_2' => [{'key' => 'val_array_hash'}]})
321
+ expect(@res).to include({'var_nested_whitespace_1' => 'val_nested_whitespace'})
322
+ expect(@res).to include({'var_nested_whitespace_2' => 'val_nested_whitespace'})
323
+ expect(@res).to include({'var_missingtarget_2' => '{{ var_missingtarget_1 }}'})
324
+ end
325
+
326
+ after do
327
+ Dir.chdir(@current_dir)
328
+ end
329
+ end
330
+
294
331
  context 'Correct operation : mistake word in ENV["HASH_BEHAVIOUR"]' do
295
332
  before do
296
333
  ENV["HASH_BEHAVIOUR"] = 'mistake_word'
@@ -390,7 +427,7 @@ describe 'merge_variablesの実行' do
390
427
  expect(@res.instance_of?(Hash)).to be_truthy
391
428
  end
392
429
 
393
- it 'exist 1 pair in Hash' do
430
+ it 'exists one pair in Hash' do
394
431
  expect(@res.length).to eq 1
395
432
  end
396
433
 
@@ -425,11 +462,11 @@ describe "load_vars_fileの実行" do
425
462
  expect(@res.instance_of?(Hash)).to be_truthy
426
463
  end
427
464
 
428
- it 'exist 1 pair in Hash' do
465
+ it 'exist one pair in Hash' do
429
466
  expect(@res.length).to eq 1
430
467
  end
431
468
 
432
- it 'exist each pair' do
469
+ it 'exists the pair' do
433
470
  expect(@res).to include({'role_var' => 'without .yml extension'})
434
471
  end
435
472
 
@@ -453,11 +490,11 @@ describe "load_vars_fileの実行" do
453
490
  expect(@res.instance_of?(Hash)).to be_truthy
454
491
  end
455
492
 
456
- it 'exist 1 pair in Hash' do
493
+ it 'exists one pair in Hash' do
457
494
  expect(@res.length).to eq 1
458
495
  end
459
496
 
460
- it 'exist each pair' do
497
+ it 'exists the pair' do
461
498
  expect(@res).to include({'role_var' => 'without .yml extension'})
462
499
  end
463
500
 
@@ -479,11 +516,11 @@ describe "load_vars_fileの実行" do
479
516
  expect(@res.instance_of?(Hash)).to be_truthy
480
517
  end
481
518
 
482
- it 'exist 1 pair in Hash' do
519
+ it 'exist two pairs in Hash' do
483
520
  expect(@res.length).to eq 2
484
521
  end
485
522
 
486
- it 'exist each pair' do
523
+ it 'exists each pair' do
487
524
  expect(@res).to include({'var1' => 'val1'})
488
525
  expect(@res).to include({'var2' => 'val2'})
489
526
  end
@@ -492,4 +529,5 @@ describe "load_vars_fileの実行" do
492
529
  Dir.chdir(@current_dir)
493
530
  end
494
531
  end
532
+
495
533
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.23
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: diff-lcs
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: serverspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: hostlist_expression
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: oj
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: winrm
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: inifile
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
@@ -145,9 +145,9 @@ executables:
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
- - .gitignore
149
- - .rspec
150
- - .travis.yml
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
151
  - CHANGELOG.md
152
152
  - Gemfile
153
153
  - LICENSE.txt
@@ -288,6 +288,9 @@ files:
288
288
  - spec/case/get_variable/inventories_env_host_vars/site.yml
289
289
  - spec/case/get_variable/playbook_only/hosts
290
290
  - spec/case/get_variable/playbook_only/site.yml
291
+ - spec/case/get_variable/resolve_variables/group_vars/all.yml
292
+ - spec/case/get_variable/resolve_variables/hosts
293
+ - spec/case/get_variable/resolve_variables/site.yml
291
294
  - spec/case/get_variable/roles_default/hosts
292
295
  - spec/case/get_variable/roles_default/roles/test/defaults/main.yml
293
296
  - spec/case/get_variable/roles_default/site.yml
@@ -323,17 +326,17 @@ require_paths:
323
326
  - lib
324
327
  required_ruby_version: !ruby/object:Gem::Requirement
325
328
  requirements:
326
- - - '>='
329
+ - - ">="
327
330
  - !ruby/object:Gem::Version
328
331
  version: '0'
329
332
  required_rubygems_version: !ruby/object:Gem::Requirement
330
333
  requirements:
331
- - - '>='
334
+ - - ">="
332
335
  - !ruby/object:Gem::Version
333
336
  version: '0'
334
337
  requirements: []
335
338
  rubyforge_project:
336
- rubygems_version: 2.1.11
339
+ rubygems_version: 2.7.6
337
340
  signing_key:
338
341
  specification_version: 4
339
342
  summary: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
@@ -463,6 +466,9 @@ test_files:
463
466
  - spec/case/get_variable/inventories_env_host_vars/site.yml
464
467
  - spec/case/get_variable/playbook_only/hosts
465
468
  - spec/case/get_variable/playbook_only/site.yml
469
+ - spec/case/get_variable/resolve_variables/group_vars/all.yml
470
+ - spec/case/get_variable/resolve_variables/hosts
471
+ - spec/case/get_variable/resolve_variables/site.yml
466
472
  - spec/case/get_variable/roles_default/hosts
467
473
  - spec/case/get_variable/roles_default/roles/test/defaults/main.yml
468
474
  - spec/case/get_variable/roles_default/site.yml