ansible_spec 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +3 -0
  4. data/lib/ansible_spec/load_ansible.rb +38 -1
  5. data/lib/ansible_spec/version.rb +1 -1
  6. data/lib/src/Rakefile +6 -0
  7. data/lib/src/spec/spec_helper.rb +2 -1
  8. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/.ansiblespec +5 -0
  9. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/dynamic_inventory.sh +43 -0
  10. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/all +1 -0
  11. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/application-servers +1 -0
  12. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/database-servers +1 -0
  13. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop +5 -0
  14. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-application-servers +1 -0
  15. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-database-servers +2 -0
  16. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-web-servers +1 -0
  17. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production +5 -0
  18. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-application-servers +1 -0
  19. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-database-servers +2 -0
  20. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-web-servers +1 -0
  21. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging +5 -0
  22. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-application-servers +1 -0
  23. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-database-servers +2 -0
  24. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-web-servers +1 -0
  25. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/web-servers +1 -0
  26. data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/site.yml +30 -0
  27. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/.ansiblespec +5 -0
  28. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/dynamic_inventory.sh +43 -0
  29. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/all +1 -0
  30. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/application-servers +1 -0
  31. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/database-servers +1 -0
  32. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop +5 -0
  33. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-application-servers +1 -0
  34. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-database-servers +2 -0
  35. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-web-servers +1 -0
  36. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production +5 -0
  37. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-application-servers +1 -0
  38. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-database-servers +2 -0
  39. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-web-servers +1 -0
  40. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging +5 -0
  41. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-application-servers +1 -0
  42. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-database-servers +2 -0
  43. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-web-servers +1 -0
  44. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/web-servers +1 -0
  45. data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/site.yml +30 -0
  46. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/.ansiblespec +5 -0
  47. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/dynamic_inventory.sh +43 -0
  48. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/all +1 -0
  49. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/application-servers +1 -0
  50. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/database-servers +1 -0
  51. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop +5 -0
  52. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-application-servers +1 -0
  53. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-database-servers +2 -0
  54. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-web-servers +1 -0
  55. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production +5 -0
  56. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-application-servers +1 -0
  57. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-database-servers +2 -0
  58. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-web-servers +1 -0
  59. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging +5 -0
  60. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-application-servers +1 -0
  61. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-database-servers +2 -0
  62. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-web-servers +1 -0
  63. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/web-servers +1 -0
  64. data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/site.yml +30 -0
  65. data/spec/dynamic_inventory_hosts_childrens_spec.rb +304 -0
  66. data/spec/dynamic_inventory_spec.rb +9 -6
  67. data/spec/ec2_dynamic_inventory_spec.rb +4 -4
  68. data/spec/get_variable_hosts_childrens_spec.rb +322 -0
  69. data/spec/inventory_parameters_spec.rb +2 -2
  70. data/spec/load_ansible_spec.rb +185 -4
  71. metadata +120 -2
@@ -0,0 +1,322 @@
1
+ # coding: utf-8
2
+ require 'fileutils'
3
+ require 'ansible_spec'
4
+ require 'pp'
5
+
6
+ describe "Dynamic Inventoryによるchildrenの依存関係を参照し、get_variablesの実行" do
7
+ context 'Correct operation : develop groups by web-serers hosts childrens' do
8
+ before do
9
+ @current_dir = Dir.pwd()
10
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_dev/')
11
+ @res = AnsibleSpec.get_variables("10.0.0.1", 0, "web-servers")
12
+ end
13
+
14
+ it 'res is hash' do
15
+ expect(@res.instance_of?(Hash)).to be_truthy
16
+ end
17
+
18
+ it 'exist 7 pair in Hash' do
19
+ expect(@res.length).to eq 7
20
+ end
21
+
22
+ it 'exist each pair' do
23
+ expect(@res).to include( {"all_variable"=>"all!!"},
24
+ {"logs_conf_file"=>"web_logs.conf"},
25
+ {"nginx_conf_file"=>"develop_nginx.conf"},
26
+ {"foo"=>"foofoo-develop"},
27
+ {"bar"=>["bar1-develop", "bar2-develop", "bar3-develop"]},
28
+ {"env_name"=>"develop"},
29
+ {"my_common_libs_version"=>"1.2"}
30
+ )
31
+ end
32
+
33
+ after do
34
+ Dir.chdir(@current_dir)
35
+ end
36
+ end
37
+
38
+ context 'Correct operation : develop groups by application-servers hosts childrens ' do
39
+ before do
40
+ @current_dir = Dir.pwd()
41
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_dev/')
42
+ @res_1st = AnsibleSpec.get_variables("10.0.0.2", 0, "application-servers")
43
+ @res_2nd = AnsibleSpec.get_variables("10.0.0.3", 0, "application-servers")
44
+ end
45
+
46
+ it 'res is hash' do
47
+ expect(@res_1st.instance_of?(Hash)).to be_truthy
48
+ expect(@res_2nd.instance_of?(Hash)).to be_truthy
49
+ end
50
+
51
+ it 'exist 7 pair in Hash' do
52
+ expect(@res_1st.length).to eq 7
53
+ expect(@res_2nd.length).to eq 7
54
+ end
55
+
56
+ it 'exist each pair' do
57
+ expect(@res_1st).to include( {"all_variable"=>"all!!"},
58
+ {"logs_conf_file"=>"application_logs.conf"},
59
+ {"java_version"=>"1.8.0_92"},
60
+ {"foo"=>"foofoo-develop"},
61
+ {"bar"=>["bar1-develop", "bar2-develop", "bar3-develop"]},
62
+ {"env_name"=>"develop"},
63
+ {"my_common_libs_version"=>"1.2"}
64
+ )
65
+ expect(@res_2nd).to include( {"all_variable"=>"all!!"},
66
+ {"logs_conf_file"=>"application_logs.conf"},
67
+ {"java_version"=>"1.8.0_92"},
68
+ {"foo"=>"foofoo-develop"},
69
+ {"bar"=>["bar1-develop", "bar2-develop", "bar3-develop"]},
70
+ {"env_name"=>"develop"},
71
+ {"my_common_libs_version"=>"1.2"}
72
+ )
73
+ end
74
+
75
+ after do
76
+ Dir.chdir(@current_dir)
77
+ end
78
+ end
79
+
80
+ context 'Correct operation : develop groups by database-servers hosts childrens ' do
81
+ before do
82
+ @current_dir = Dir.pwd()
83
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_dev/')
84
+ @res = AnsibleSpec.get_variables("10.0.0.4", 0, "database-servers")
85
+ end
86
+
87
+ it 'res is hash' do
88
+ expect(@res.instance_of?(Hash)).to be_truthy
89
+ end
90
+
91
+ it 'exist 8 pair in Hash' do
92
+ expect(@res.length).to eq 8
93
+ end
94
+
95
+ it 'exist each pair' do
96
+ expect(@res).to include( {"all_variable"=>"all!!"},
97
+ {"bar"=>["bar1-develop", "bar2-develop", "bar3-develop"]},
98
+ {"env_name"=>"develop"},
99
+ {"foo"=>"foofoo-develop"},
100
+ {"logs_conf_file"=>"database_logs.conf"},
101
+ {"my_common_libs_version"=>"1.2"},
102
+ {"mysql_version"=>"5.7.12"},
103
+ {"mysql_dependencies_libs"=>["foo-v2","bar-v2"]}
104
+ )
105
+ end
106
+
107
+ after do
108
+ Dir.chdir(@current_dir)
109
+ end
110
+ end
111
+
112
+ context 'Correct operation : staging groups by web-serers hosts childrens' do
113
+ before do
114
+ @current_dir = Dir.pwd()
115
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_stg/')
116
+ @res = AnsibleSpec.get_variables("10.0.0.1", 0, "web-servers")
117
+ end
118
+
119
+ it 'res is hash' do
120
+ expect(@res.instance_of?(Hash)).to be_truthy
121
+ end
122
+
123
+ it 'exist 7 pair in Hash' do
124
+ expect(@res.length).to eq 7
125
+ end
126
+
127
+ it 'exist each pair' do
128
+ expect(@res).to include( {"all_variable"=>"all!!"},
129
+ {"logs_conf_file"=>"web_logs.conf"},
130
+ {"nginx_conf_file"=>"staging_nginx.conf"},
131
+ {"foo"=>"foofoo-staging"},
132
+ {"bar"=>["bar1-staging", "bar2-staging", "bar3-staging"]},
133
+ {"env_name"=>"staging"},
134
+ {"my_common_libs_version"=>"1.1"}
135
+ )
136
+ end
137
+
138
+ after do
139
+ Dir.chdir(@current_dir)
140
+ end
141
+ end
142
+
143
+ context 'Correct operation : staging groups by application-servers hosts childrens ' do
144
+ before do
145
+ @current_dir = Dir.pwd()
146
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_stg/')
147
+ @res_1st = AnsibleSpec.get_variables("10.0.0.2", 0, "application-servers")
148
+ @res_2nd = AnsibleSpec.get_variables("10.0.0.3", 0, "application-servers")
149
+ end
150
+
151
+ it 'res is hash' do
152
+ expect(@res_1st.instance_of?(Hash)).to be_truthy
153
+ expect(@res_2nd.instance_of?(Hash)).to be_truthy
154
+ end
155
+
156
+ it 'exist 7 pair in Hash' do
157
+ expect(@res_1st.length).to eq 7
158
+ expect(@res_2nd.length).to eq 7
159
+ end
160
+
161
+ it 'exist each pair' do
162
+ expect(@res_1st).to include( {"all_variable"=>"all!!"},
163
+ {"logs_conf_file"=>"application_logs.conf"},
164
+ {"java_version"=>"1.8.0_66"},
165
+ {"foo"=>"foofoo-staging"},
166
+ {"bar"=>["bar1-staging", "bar2-staging", "bar3-staging"]},
167
+ {"env_name"=>"staging"},
168
+ {"my_common_libs_version"=>"1.1"}
169
+ )
170
+ expect(@res_2nd).to include( {"all_variable"=>"all!!"},
171
+ {"logs_conf_file"=>"application_logs.conf"},
172
+ {"java_version"=>"1.8.0_66"},
173
+ {"foo"=>"foofoo-staging"},
174
+ {"bar"=>["bar1-staging", "bar2-staging", "bar3-staging"]},
175
+ {"env_name"=>"staging"},
176
+ {"my_common_libs_version"=>"1.1"}
177
+ )
178
+ end
179
+
180
+ after do
181
+ Dir.chdir(@current_dir)
182
+ end
183
+ end
184
+
185
+ context 'Correct operation : staging groups by database-servers hosts childrens ' do
186
+ before do
187
+ @current_dir = Dir.pwd()
188
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_stg/')
189
+ @res = AnsibleSpec.get_variables("10.0.0.4", 0, "database-servers")
190
+ end
191
+
192
+ it 'res is hash' do
193
+ expect(@res.instance_of?(Hash)).to be_truthy
194
+ end
195
+
196
+ it 'exist 8 pair in Hash' do
197
+ expect(@res.length).to eq 8
198
+ end
199
+
200
+ it 'exist each pair' do
201
+ expect(@res).to include( {"all_variable"=>"all!!"},
202
+ {"bar"=>["bar1-staging", "bar2-staging", "bar3-staging"]},
203
+ {"env_name"=>"staging"},
204
+ {"foo"=>"foofoo-staging"},
205
+ {"logs_conf_file"=>"database_logs.conf"},
206
+ {"my_common_libs_version"=>"1.1"},
207
+ {"mysql_version"=>"5.6.30"},
208
+ {"mysql_dependencies_libs"=>["foo-v1","bar-v1"]}
209
+ )
210
+ end
211
+
212
+ after do
213
+ Dir.chdir(@current_dir)
214
+ end
215
+ end
216
+
217
+ context 'Correct operation : production groups by web-serers hosts childrens' do
218
+ before do
219
+ @current_dir = Dir.pwd()
220
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_prd/')
221
+ @res = AnsibleSpec.get_variables("10.0.0.1", 0, "web-servers")
222
+ end
223
+
224
+ it 'res is hash' do
225
+ expect(@res.instance_of?(Hash)).to be_truthy
226
+ end
227
+
228
+ it 'exist 7 pair in Hash' do
229
+ expect(@res.length).to eq 7
230
+ end
231
+
232
+ it 'exist each pair' do
233
+ expect(@res).to include( {"all_variable"=>"all!!"},
234
+ {"logs_conf_file"=>"web_logs.conf"},
235
+ {"nginx_conf_file"=>"production_nginx.conf"},
236
+ {"foo"=>"foofoo-production"},
237
+ {"bar"=>["bar1-production", "bar2-production", "bar3-production"]},
238
+ {"env_name"=>"production"},
239
+ {"my_common_libs_version"=>"1.0"}
240
+ )
241
+ end
242
+
243
+ after do
244
+ Dir.chdir(@current_dir)
245
+ end
246
+ end
247
+
248
+ context 'Correct operation : production groups by application-servers hosts childrens ' do
249
+ before do
250
+ @current_dir = Dir.pwd()
251
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_prd/')
252
+ @res_1st = AnsibleSpec.get_variables("10.0.0.2", 0, "application-servers")
253
+ @res_2nd = AnsibleSpec.get_variables("10.0.0.3", 0, "application-servers")
254
+ end
255
+
256
+ it 'res is hash' do
257
+ expect(@res_1st.instance_of?(Hash)).to be_truthy
258
+ expect(@res_2nd.instance_of?(Hash)).to be_truthy
259
+ end
260
+
261
+ it 'exist 7 pair in Hash' do
262
+ expect(@res_1st.length).to eq 7
263
+ expect(@res_2nd.length).to eq 7
264
+ end
265
+
266
+ it 'exist each pair' do
267
+ expect(@res_1st).to include( {"all_variable"=>"all!!"},
268
+ {"logs_conf_file"=>"application_logs.conf"},
269
+ {"java_version"=>"1.8.0_45"},
270
+ {"foo"=>"foofoo-production"},
271
+ {"bar"=>["bar1-production", "bar2-production", "bar3-production"]},
272
+ {"env_name"=>"production"},
273
+ {"my_common_libs_version"=>"1.0"}
274
+ )
275
+ expect(@res_2nd).to include( {"all_variable"=>"all!!"},
276
+ {"logs_conf_file"=>"application_logs.conf"},
277
+ {"java_version"=>"1.8.0_45"},
278
+ {"foo"=>"foofoo-production"},
279
+ {"bar"=>["bar1-production", "bar2-production", "bar3-production"]},
280
+ {"env_name"=>"production"},
281
+ {"my_common_libs_version"=>"1.0"}
282
+ )
283
+ end
284
+
285
+ after do
286
+ Dir.chdir(@current_dir)
287
+ end
288
+ end
289
+
290
+ context 'Correct operation : production groups by database-servers hosts childrens ' do
291
+ before do
292
+ @current_dir = Dir.pwd()
293
+ Dir.chdir('spec/case/get_variable/group_vars_hosts_childrens_env_prd/')
294
+ @res = AnsibleSpec.get_variables("10.0.0.4", 0, "database-servers")
295
+ end
296
+
297
+ it 'res is hash' do
298
+ expect(@res.instance_of?(Hash)).to be_truthy
299
+ end
300
+
301
+ it 'exist 8 pair in Hash' do
302
+ expect(@res.length).to eq 8
303
+ end
304
+
305
+ it 'exist each pair' do
306
+ expect(@res).to include( {"all_variable"=>"all!!"},
307
+ {"bar"=>["bar1-production", "bar2-production", "bar3-production"]},
308
+ {"env_name"=>"production"},
309
+ {"foo"=>"foofoo-production"},
310
+ {"logs_conf_file"=>"database_logs.conf"},
311
+ {"my_common_libs_version"=>"1.0"},
312
+ {"mysql_version"=>"5.6.30"},
313
+ {"mysql_dependencies_libs"=>["foo-v1","bar-v1"]}
314
+ )
315
+ end
316
+
317
+ after do
318
+ Dir.chdir(@current_dir)
319
+ end
320
+ end
321
+
322
+ end
@@ -142,8 +142,8 @@ describe "get_propertiesの実行" do
142
142
  expect(@res[0].instance_of?(Hash)).to be_truthy
143
143
  end
144
144
 
145
- it 'check 5 group' do
146
- expect(@res[0].length).to eq 5
145
+ it 'check 6 group' do
146
+ expect(@res[0].length).to eq 6
147
147
  end
148
148
 
149
149
  it 'exist name' do
@@ -1191,8 +1191,8 @@ EOF
1191
1191
  expect(@res[0].instance_of?(Hash)).to be_truthy
1192
1192
  end
1193
1193
 
1194
- it 'check 5 group' do
1195
- expect(@res[0].length).to eq 5
1194
+ it 'check 6 group' do
1195
+ expect(@res[0].length).to eq 6
1196
1196
  end
1197
1197
 
1198
1198
  it 'exist name' do
@@ -1276,8 +1276,8 @@ EOF
1276
1276
  expect(@res[0].instance_of?(Hash)).to be_truthy
1277
1277
  end
1278
1278
 
1279
- it 'check 5 group' do
1280
- expect(@res[0].length).to eq 5
1279
+ it 'check 6 group' do
1280
+ expect(@res[0].length).to eq 6
1281
1281
  end
1282
1282
 
1283
1283
  it 'exist name' do
@@ -1370,4 +1370,185 @@ EOF
1370
1370
  File.delete(tmp_hosts)
1371
1371
  end
1372
1372
  end
1373
+
1374
+ context '正常系 (hosts 複数指定)' do
1375
+ require 'yaml'
1376
+ tmp_ansiblespec = '.ansiblespec'
1377
+ tmp_playbook = 'site.yml'
1378
+ tmp_hosts = 'hosts'
1379
+
1380
+ before do
1381
+
1382
+ content = <<'EOF'
1383
+ ---
1384
+ -
1385
+ playbook: site.yml
1386
+ inventory: hosts
1387
+ EOF
1388
+
1389
+ content_p = <<'EOF'
1390
+ - name: Ansible-Sample-TDD
1391
+ hosts:
1392
+ - server
1393
+ - server2
1394
+ user: root
1395
+ roles:
1396
+ - nginx
1397
+ - mariadb
1398
+ EOF
1399
+
1400
+ content_h = <<'EOF'
1401
+ [server]
1402
+ 192.168.0.103
1403
+ 192.168.0.104
1404
+ [server2]
1405
+ 192.168.0.105
1406
+ 192.168.0.106
1407
+ EOF
1408
+
1409
+ create_file(tmp_ansiblespec,content)
1410
+ create_file(tmp_playbook,content_p)
1411
+ create_file(tmp_hosts,content_h)
1412
+ @res = AnsibleSpec.get_properties
1413
+ end
1414
+
1415
+ it 'res is array' do
1416
+ expect(@res.instance_of?(Array)).to be_truthy
1417
+ end
1418
+
1419
+ it 'res[0] is hash' do
1420
+ expect(@res[0].instance_of?(Hash)).to be_truthy
1421
+ end
1422
+
1423
+ it 'check 6 group' do
1424
+ expect(@res[0].length).to eq 6
1425
+ end
1426
+
1427
+ it 'exist name' do
1428
+ expect(@res[0].key?('name')).to be_truthy
1429
+ expect(@res[0]['name']).to eq 'Ansible-Sample-TDD'
1430
+ end
1431
+
1432
+ it 'exist hosts' do
1433
+ expect(@res[0]['hosts'].instance_of?(Array)).to be_truthy
1434
+ expect([{'name' => '192.168.0.103',
1435
+ 'uri' => '192.168.0.103',
1436
+ 'port' => 22,
1437
+ 'hosts'=>'server'},
1438
+ {'name' => '192.168.0.104',
1439
+ 'uri' => '192.168.0.104',
1440
+ 'port' => 22,
1441
+ 'hosts'=>'server'},
1442
+ {'name' => '192.168.0.105',
1443
+ 'uri' => '192.168.0.105',
1444
+ 'port' => 22,
1445
+ 'hosts'=>'server2'},
1446
+ {'name' => '192.168.0.106',
1447
+ 'uri' => '192.168.0.106',
1448
+ 'port' => 22,
1449
+ 'hosts'=>'server2'}]).to match_array(@res[0]['hosts'])
1450
+ end
1451
+
1452
+ it 'exist user' do
1453
+ expect(@res[0].key?('user')).to be_truthy
1454
+ expect(@res[0]['user']).to eq 'root'
1455
+ end
1456
+
1457
+ it 'exist roles' do
1458
+ expect(@res[0].key?('roles')).to be_truthy
1459
+ expect(@res[0]['roles'].instance_of?(Array)).to be_truthy
1460
+ expect(@res[0]['roles'][0]).to eq 'nginx'
1461
+ expect(@res[0]['roles'][1]).to eq 'mariadb'
1462
+ end
1463
+
1464
+ after do
1465
+ File.delete(tmp_ansiblespec)
1466
+ File.delete(tmp_playbook)
1467
+ File.delete(tmp_hosts)
1468
+ end
1469
+ end
1470
+
1471
+ context '正常系 (hosts 複数指定)ホストがグループにない場合タスクをスキップ' do
1472
+ require 'yaml'
1473
+ tmp_ansiblespec = '.ansiblespec'
1474
+ tmp_playbook = 'site.yml'
1475
+ tmp_hosts = 'hosts'
1476
+
1477
+ before do
1478
+
1479
+ content = <<'EOF'
1480
+ ---
1481
+ -
1482
+ playbook: site.yml
1483
+ inventory: hosts
1484
+ EOF
1485
+
1486
+ content_p = <<'EOF'
1487
+ - name: Ansible-Sample-TDD-1
1488
+ hosts:
1489
+ - server
1490
+ user: root
1491
+ roles:
1492
+ - role: nginx
1493
+ - role: mariadb
1494
+ - name: Ansible-Sample-TDD-3-None-Servers
1495
+ hosts:
1496
+ - server3
1497
+ user: root
1498
+ roles:
1499
+ - role: nginx
1500
+ - role: mariadb
1501
+ - name: Ansible-Sample-TDD-2
1502
+ hosts:
1503
+ - server2
1504
+ user: root
1505
+ roles:
1506
+ - role: nginx
1507
+ - role: mariadb
1508
+ EOF
1509
+
1510
+ content_h = <<'EOF'
1511
+ [server]
1512
+ 192.168.0.103
1513
+ 192.168.0.104
1514
+ [server3]
1515
+ [server2]
1516
+ 192.168.0.105
1517
+ 192.168.0.106
1518
+ EOF
1519
+
1520
+ create_file(tmp_ansiblespec,content)
1521
+ create_file(tmp_playbook,content_p)
1522
+ create_file(tmp_hosts,content_h)
1523
+ @res = AnsibleSpec.get_properties
1524
+ end
1525
+
1526
+ it 'res is array' do
1527
+ expect(@res.instance_of?(Array)).to be_truthy
1528
+ end
1529
+
1530
+ it 'res[0] is hash' do
1531
+ expect(@res[0].instance_of?(Hash)).to be_truthy
1532
+ end
1533
+
1534
+ it 'check 6 group' do
1535
+ expect(@res[0].length).to eq 6
1536
+ end
1537
+
1538
+ it 'exist name' do
1539
+ expect(@res[0].key?('name')).to be_truthy
1540
+ expect(@res[0]['name']).to eq 'Ansible-Sample-TDD-1'
1541
+ # if empty host in target groups(hosts), skip task.
1542
+ #expect(@res[1].key?('name')).to be_truthy
1543
+ #expect(@res[1]['name']).to eq 'Ansible-Sample-TDD-3-None-Servers'
1544
+ expect(@res[1].key?('name')).to be_truthy
1545
+ expect(@res[1]['name']).to eq 'Ansible-Sample-TDD-2'
1546
+ end
1547
+
1548
+ after do
1549
+ File.delete(tmp_ansiblespec)
1550
+ File.delete(tmp_playbook)
1551
+ File.delete(tmp_hosts)
1552
+ end
1553
+ end
1373
1554
  end