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,5 @@
1
+ foo: "foofoo-develop"
2
+ bar: ["bar1-develop", "bar2-develop", "bar3-develop"]
3
+ env_name: "develop"
4
+
5
+ my_common_libs_version: "1.2"
@@ -0,0 +1,2 @@
1
+ mysql_version: "5.7.12"
2
+ mysql_dependencies_libs: ["foo-v2","bar-v2"]
@@ -0,0 +1,5 @@
1
+ foo: "foofoo-production"
2
+ bar: ["bar1-production", "bar2-production", "bar3-production"]
3
+ env_name: "production"
4
+
5
+ my_common_libs_version: "1.0"
@@ -0,0 +1,2 @@
1
+ mysql_version: "5.6.30"
2
+ mysql_dependencies_libs: ["foo-v1","bar-v1"]
@@ -0,0 +1,5 @@
1
+ foo: "foofoo-staging"
2
+ bar: ["bar1-staging", "bar2-staging", "bar3-staging"]
3
+ env_name: "staging"
4
+
5
+ my_common_libs_version: "1.1"
@@ -0,0 +1,2 @@
1
+ mysql_version: "5.6.30"
2
+ mysql_dependencies_libs: ["foo-v1","bar-v1"]
@@ -0,0 +1,30 @@
1
+ #- name: install-logcollect-libs
2
+ # hosts:
3
+ # - web-servers
4
+ # - database-servers
5
+ # - application-servers
6
+ # connection: local
7
+ # roles:
8
+ # - test
9
+
10
+ - name: install-nginx
11
+ hosts:
12
+ - web-servers
13
+ connection: local
14
+ roles:
15
+ - test
16
+
17
+ #- name: install-java
18
+ # hosts:
19
+ # - application-servers
20
+ # connection: local
21
+ # roles:
22
+ # - test
23
+ #
24
+ #- name: install-mysql
25
+ # hosts:
26
+ # - database-servers
27
+ # connection: local
28
+ # roles:
29
+ # - test
30
+
@@ -0,0 +1,304 @@
1
+ # coding: utf-8
2
+ require 'ansible_spec'
3
+
4
+ describe "Dynamic InventoryでChildren関係でhostsを指定しload_targetsの実行" do
5
+ context '正常系:develop-env DynamicInventory:8 Group, 2 hosts' do
6
+ tmp_hosts = 'hosts'
7
+ before do
8
+ content_h = <<'EOF'
9
+
10
+ #!/bin/bash
11
+ #echo '{"database-servers": {"hosts": ["host1.example.com"],"vars":{"a": true}}}'
12
+ cat << EOS
13
+ {
14
+ "database-servers": {
15
+ "hosts": [
16
+ "10.0.0.4"
17
+ ]
18
+ },
19
+ "application-servers": {
20
+ "hosts": []
21
+ },
22
+ "web-servers": {
23
+ "hosts": [
24
+ "10.0.0.1"
25
+ ]
26
+ },
27
+ "develop-database-servers": {
28
+ "children": [
29
+ "database-servers"
30
+ ]
31
+ },
32
+ "develop-application-servers": {
33
+ "children": [
34
+ "application-servers"
35
+ ]
36
+ },
37
+ "develop-web-servers": {
38
+ "children": [
39
+ "web-servers"
40
+ ]
41
+ },
42
+ "develop": {
43
+ "children": [
44
+ "develop-web-servers",
45
+ "develop-application-servers",
46
+ "develop-database-servers"
47
+ ]
48
+ }
49
+ }
50
+ EOS
51
+ EOF
52
+ create_file(tmp_hosts,content_h)
53
+ File.chmod(0755,tmp_hosts)
54
+ @res = AnsibleSpec.load_targets(tmp_hosts)
55
+ end
56
+
57
+ it 'res is hash' do
58
+ expect(@res.instance_of?(Hash)).to be_truthy
59
+ end
60
+
61
+ it 'exist 8 group' do
62
+ expect(@res.length).to eq 8
63
+ end
64
+
65
+ it 'exist group' do
66
+ expect(@res.key?('hosts_childrens')).to be_truthy
67
+ expect(@res.key?('database-servers')).to be_truthy
68
+ expect(@res.key?('web-servers')).to be_truthy
69
+ expect(@res.key?('application-servers')).to be_truthy
70
+ expect(@res.key?('develop-database-servers')).to be_truthy
71
+ expect(@res.key?('develop-application-servers')).to be_truthy
72
+ expect(@res.key?('develop-web-servers')).to be_truthy
73
+ expect(@res.key?('develop')).to be_truthy
74
+ end
75
+
76
+ it 'database-servers 10.0.0.4' do
77
+ obj = @res['database-servers'][0]
78
+ expect(obj.instance_of?(Hash)).to be_truthy
79
+ expect(obj).to include({'uri' => '10.0.0.4',
80
+ 'port' => 22})
81
+ end
82
+
83
+ it 'application-servers empty' do
84
+ obj = @res['application-servers'][0]
85
+ expect(obj).to be_nil
86
+ end
87
+
88
+ it 'web-servers 10.0.0.1' do
89
+ obj = @res['web-servers'][0]
90
+ expect(obj.instance_of?(Hash)).to be_truthy
91
+ expect(obj).to include({'uri' => '10.0.0.1',
92
+ 'port' => 22})
93
+ end
94
+
95
+ after do
96
+ File.delete(tmp_hosts)
97
+ end
98
+ end
99
+
100
+ context '正常系:staging-env DynamicInventory:8 Group, 3 hosts' do
101
+ tmp_hosts = 'hosts'
102
+ before do
103
+ content_h = <<'EOF'
104
+ #!/bin/bash
105
+ #echo '{"database-servers": {"hosts": ["host1.example.com", "host2.example.com"],"vars":{"a": true}}}'
106
+ cat << EOS
107
+ {
108
+ "database-servers": {
109
+ "hosts": [
110
+ "10.1.0.4"
111
+ ]
112
+ },
113
+ "application-servers": {
114
+ "hosts": [
115
+ "10.1.0.2"
116
+ ]
117
+ },
118
+ "web-servers": {
119
+ "hosts": [
120
+ "10.1.0.1"
121
+ ]
122
+ },
123
+ "staging-database-servers": {
124
+ "children": [
125
+ "database-servers"
126
+ ]
127
+ },
128
+ "staging-application-servers": {
129
+ "children": [
130
+ "application-servers"
131
+ ]
132
+ },
133
+ "staging-web-servers": {
134
+ "children": [
135
+ "web-servers"
136
+ ]
137
+ },
138
+ "staging": {
139
+ "children": [
140
+ "staging-web-servers",
141
+ "staging-application-servers",
142
+ "staging-database-servers"
143
+ ]
144
+ }
145
+ }
146
+ EOS
147
+ EOF
148
+ create_file(tmp_hosts,content_h)
149
+ File.chmod(0755,tmp_hosts)
150
+ @res = AnsibleSpec.load_targets(tmp_hosts)
151
+ end
152
+
153
+ it 'res is hash' do
154
+ expect(@res.instance_of?(Hash)).to be_truthy
155
+ end
156
+
157
+ it 'exist 8 group' do
158
+ expect(@res.length).to eq 8
159
+ end
160
+
161
+ it 'exist group' do
162
+ expect(@res.key?('hosts_childrens')).to be_truthy
163
+ expect(@res.key?('database-servers')).to be_truthy
164
+ expect(@res.key?('web-servers')).to be_truthy
165
+ expect(@res.key?('application-servers')).to be_truthy
166
+ expect(@res.key?('staging-database-servers')).to be_truthy
167
+ expect(@res.key?('staging-application-servers')).to be_truthy
168
+ expect(@res.key?('staging-web-servers')).to be_truthy
169
+ expect(@res.key?('staging')).to be_truthy
170
+ end
171
+
172
+ it 'database-servers 10.1.0.4' do
173
+ obj = @res['database-servers'][0]
174
+ expect(obj.instance_of?(Hash)).to be_truthy
175
+ expect(obj).to include({'uri' => '10.1.0.4',
176
+ 'port' => 22})
177
+ end
178
+
179
+ it 'application-servers 10.1.0.1' do
180
+ obj = @res['application-servers'][0]
181
+ expect(obj.instance_of?(Hash)).to be_truthy
182
+ expect(obj).to include({'uri' => '10.1.0.2',
183
+ 'port' => 22})
184
+ end
185
+
186
+
187
+ it 'web-servers 10.1.0.1' do
188
+ obj = @res['web-servers'][0]
189
+ expect(obj.instance_of?(Hash)).to be_truthy
190
+ expect(obj).to include({'uri' => '10.1.0.1',
191
+ 'port' => 22})
192
+ end
193
+
194
+ after do
195
+ File.delete(tmp_hosts)
196
+ end
197
+ end
198
+ context '正常系:production-env DynamicInventory:8 Group, 4 hosts. but no vars' do
199
+ tmp_hosts = 'hosts'
200
+ before do
201
+ content_h = <<'EOF'
202
+ #!/bin/bash
203
+ #echo '{"web-servers": [ "host2.example.com", "host3.example.com" ]}'
204
+ cat << EOS
205
+ {
206
+ "database-servers": {
207
+ "hosts": [
208
+ "10.2.0.4"
209
+ ]
210
+ },
211
+ "application-servers": {
212
+ "hosts": [
213
+ "10.2.0.2",
214
+ "10.2.0.3"
215
+ ]
216
+ },
217
+ "web-servers": {
218
+ "hosts": [
219
+ "10.2.0.1"
220
+ ]
221
+ },
222
+ "production-database-servers": {
223
+ "children": [
224
+ "database-servers"
225
+ ]
226
+ },
227
+ "production-application-servers": {
228
+ "children": [
229
+ "application-servers"
230
+ ]
231
+ },
232
+ "production-web-servers": {
233
+ "children": [
234
+ "web-servers"
235
+ ]
236
+ },
237
+ "production": {
238
+ "children": [
239
+ "production-web-servers",
240
+ "production-application-servers",
241
+ "production-database-servers"
242
+ ]
243
+ }
244
+ }
245
+ EOS
246
+ EOF
247
+ create_file(tmp_hosts,content_h)
248
+ File.chmod(0755,tmp_hosts)
249
+ @res = AnsibleSpec.load_targets(tmp_hosts)
250
+ end
251
+
252
+ it 'res is hash' do
253
+ expect(@res.instance_of?(Hash)).to be_truthy
254
+ end
255
+
256
+ it 'exist 8 group' do
257
+ expect(@res.length).to eq 8
258
+ end
259
+
260
+ it 'exist group' do
261
+ expect(@res.key?('hosts_childrens')).to be_truthy
262
+ expect(@res.key?('database-servers')).to be_truthy
263
+ expect(@res.key?('web-servers')).to be_truthy
264
+ expect(@res.key?('application-servers')).to be_truthy
265
+ expect(@res.key?('production-database-servers')).to be_truthy
266
+ expect(@res.key?('production-application-servers')).to be_truthy
267
+ expect(@res.key?('production-web-servers')).to be_truthy
268
+ expect(@res.key?('production')).to be_truthy
269
+ end
270
+
271
+ it 'database-servers 10.2.0.4' do
272
+ obj = @res['database-servers'][0]
273
+ expect(obj.instance_of?(Hash)).to be_truthy
274
+ expect(obj).to include({'uri' => '10.2.0.4',
275
+ 'port' => 22})
276
+ end
277
+
278
+ it 'application-servers 10.2.0.2' do
279
+ obj = @res['application-servers'][0]
280
+ expect(obj.instance_of?(Hash)).to be_truthy
281
+ expect(obj).to include({'uri' => '10.2.0.2',
282
+ 'port' => 22})
283
+ end
284
+
285
+ it 'aplication-servers 10.2.0.3' do
286
+ obj = @res['application-servers'][1]
287
+ expect(obj.instance_of?(Hash)).to be_truthy
288
+ expect(obj).to include({'uri' => '10.2.0.3',
289
+ 'port' => 22})
290
+ end
291
+
292
+ it 'web-servers 10.2.0.1' do
293
+ obj = @res['web-servers'][0]
294
+ expect(obj.instance_of?(Hash)).to be_truthy
295
+ expect(obj).to include({'uri' => '10.2.0.1',
296
+ 'port' => 22})
297
+ end
298
+
299
+ after do
300
+ File.delete(tmp_hosts)
301
+ end
302
+ end
303
+ end
304
+
@@ -18,12 +18,13 @@ EOF
18
18
  expect(@res.instance_of?(Hash)).to be_truthy
19
19
  end
20
20
 
21
- it 'exist 1 group' do
22
- expect(@res.length).to eq 1
21
+ it 'exist 2 group' do
22
+ expect(@res.length).to eq 2
23
23
  end
24
24
 
25
25
  it 'exist group' do
26
26
  expect(@res.key?('databases')).to be_truthy
27
+ expect(@res.key?('hosts_childrens')).to be_truthy
27
28
  end
28
29
 
29
30
  it 'databases host1.example.com' do
@@ -54,12 +55,13 @@ EOF
54
55
  expect(@res.instance_of?(Hash)).to be_truthy
55
56
  end
56
57
 
57
- it 'exist 1 group' do
58
- expect(@res.length).to eq 1
58
+ it 'exist 2 group' do
59
+ expect(@res.length).to eq 2
59
60
  end
60
61
 
61
62
  it 'exist group' do
62
63
  expect(@res.key?('databases')).to be_truthy
64
+ expect(@res.key?('hosts_childrens')).to be_truthy
63
65
  end
64
66
 
65
67
  it 'databases host1.example.com' do
@@ -96,12 +98,13 @@ EOF
96
98
  expect(@res.instance_of?(Hash)).to be_truthy
97
99
  end
98
100
 
99
- it 'exist 1 group' do
100
- expect(@res.length).to eq 1
101
+ it 'exist 2 group' do
102
+ expect(@res.length).to eq 2
101
103
  end
102
104
 
103
105
  it 'exist group' do
104
106
  expect(@res.key?('webservers')).to be_truthy
107
+ expect(@res.key?('hosts_childrens')).to be_truthy
105
108
  end
106
109
 
107
110
  it 'databases host1.example.com' do
@@ -18,8 +18,8 @@ EOF
18
18
  expect(@res.instance_of?(Hash)).to be_truthy
19
19
  end
20
20
 
21
- it 'contains 2 groups' do
22
- expect(@res.length).to eq 2
21
+ it 'contains 3 groups' do
22
+ expect(@res.length).to eq 3
23
23
  end
24
24
 
25
25
  it 'contains key tag_some_other_key1' do
@@ -68,8 +68,8 @@ EOF
68
68
  expect(@res.instance_of?(Hash)).to be_truthy
69
69
  end
70
70
 
71
- it 'contains 1 groups' do
72
- expect(@res.length).to eq 1
71
+ it 'contains 2 groups' do
72
+ expect(@res.length).to eq 2
73
73
  end
74
74
 
75
75
  it 'contains key tag_Name_sample_app' do