ansible_spec 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/lib/ansible_spec/load_ansible.rb +20 -0
- data/lib/ansible_spec/version.rb +1 -1
- data/lib/src/Rakefile +7 -2
- data/spec/dependency_spec.rb +67 -0
- data/spec/load_ansible_spec.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f3f3fdce96a604720925a233a0b2cf0f11caf0b
|
4
|
+
data.tar.gz: aa92bf9f29d175293cb755145fb8e4b6123e6f63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a6ec70aaf382a4bd991536b02a56d767401477ce9def30cf71ec3320fb857880a7b9386f15f661e0300a1796b827f54cb0b2dc5dfafc8022d50799bc8dd819
|
7
|
+
data.tar.gz: 9b78e44c7fcad0d64324465311a6126ff911e931dd0b8e0af599d23a66d150dace9a4a16a76ff4287cfd8bb5263c305f89611daa6bbef1e99314fe5ad2186843
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# v0.2.6
|
2
|
+
- Merge [#53 Execute tests for dependent roles](https://github.com/volanja/ansible_spec/pull/53) by [Gerrrr](https://github.com/Gerrrr)
|
3
|
+
|
1
4
|
# v0.2.5
|
2
|
-
-
|
5
|
+
- Merge [#51 Handle hosts which are not assigned to any group](https://github.com/volanja/ansible_spec/pull/51) by [Gerrrr](https://github.com/Gerrrr)
|
3
6
|
|
4
7
|
# v0.2.4
|
5
8
|
- Fix [#50 do not fail on no hosts matched](https://github.com/volanja/ansible_spec/pull/50) by [phiche](https://github.com/phiche)
|
@@ -175,6 +175,26 @@ module AnsibleSpec
|
|
175
175
|
return playbook, inventoryfile
|
176
176
|
end
|
177
177
|
|
178
|
+
# param: role
|
179
|
+
# return: ["role1", "role2"]
|
180
|
+
def self.load_dependencies(role)
|
181
|
+
role_queue = [role]
|
182
|
+
deps = []
|
183
|
+
until role_queue.empty?
|
184
|
+
role = role_queue.pop()
|
185
|
+
path = File.join("./", "roles", role, "meta", "main.yml")
|
186
|
+
|
187
|
+
if File.exist?(path)
|
188
|
+
new_deps = YAML.load_file(path).fetch("dependencies", []).map { |h|
|
189
|
+
h["role"]
|
190
|
+
}
|
191
|
+
role_queue.concat(new_deps)
|
192
|
+
deps.concat(new_deps)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
return deps
|
196
|
+
end
|
197
|
+
|
178
198
|
# param: playbook
|
179
199
|
# return: json
|
180
200
|
# {"name"=>"Ansible-Sample-TDD", "hosts"=>"server", "user"=>"root", "roles"=>["nginx", "mariadb"]}
|
data/lib/ansible_spec/version.rb
CHANGED
data/lib/src/Rakefile
CHANGED
@@ -21,9 +21,14 @@ namespace :serverspec do
|
|
21
21
|
else
|
22
22
|
ENV['TARGET_USER'] = property["user"]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
roles = property["roles"]
|
26
|
+
for role in property["roles"]
|
27
|
+
deps = AnsibleSpec.load_dependencies(role)
|
28
|
+
roles += deps
|
29
|
+
end
|
30
|
+
t.pattern = 'roles/{' + roles.join(',') + '}/spec/*_spec.rb'
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
29
|
-
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'ansible_spec'
|
3
|
+
|
4
|
+
|
5
|
+
describe "load_dependencies" do
|
6
|
+
tmp_hosts = 'hosts'
|
7
|
+
tmp_ansiblespec = '.ansiblespec'
|
8
|
+
tmp_playbook = 'site.yml'
|
9
|
+
tmp_webapp_meta = 'roles/webapp/meta/main.yml'
|
10
|
+
tmp_dep1_meta = 'roles/dep1/meta/main.yml'
|
11
|
+
|
12
|
+
spec_content = <<'EOF'
|
13
|
+
---
|
14
|
+
-
|
15
|
+
playbook: site.yml
|
16
|
+
inventory: hosts
|
17
|
+
EOF
|
18
|
+
|
19
|
+
hosts_content = <<'EOF'
|
20
|
+
[normal]
|
21
|
+
192.168.0.1
|
22
|
+
192.168.0.2
|
23
|
+
192.168.0.3
|
24
|
+
EOF
|
25
|
+
|
26
|
+
playbook_content = <<'EOF'
|
27
|
+
- name: Ansible-Sample-TDD
|
28
|
+
hosts: normal
|
29
|
+
user: root
|
30
|
+
roles:
|
31
|
+
- webapp
|
32
|
+
EOF
|
33
|
+
|
34
|
+
webapp_meta_content = <<'EOF'
|
35
|
+
---
|
36
|
+
dependencies:
|
37
|
+
- { role: dep1 }
|
38
|
+
- { role: dep2 }
|
39
|
+
EOF
|
40
|
+
|
41
|
+
dep1_meta_content = <<'EOF'
|
42
|
+
---
|
43
|
+
dependencies:
|
44
|
+
- { role: dep3 }
|
45
|
+
EOF
|
46
|
+
|
47
|
+
before do
|
48
|
+
create_file(tmp_hosts, hosts_content)
|
49
|
+
create_file(tmp_ansiblespec, spec_content)
|
50
|
+
create_file(tmp_playbook, playbook_content)
|
51
|
+
create_file(tmp_webapp_meta, webapp_meta_content)
|
52
|
+
create_file(tmp_dep1_meta, dep1_meta_content)
|
53
|
+
@deps = AnsibleSpec.load_dependencies("webapp")
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should correctly resolve nested dependencies' do
|
57
|
+
expect(@deps).to eq ["dep1", "dep2", "dep3"]
|
58
|
+
end
|
59
|
+
|
60
|
+
after do
|
61
|
+
File.delete(tmp_hosts)
|
62
|
+
File.delete(tmp_ansiblespec)
|
63
|
+
File.delete(tmp_playbook)
|
64
|
+
File.delete(tmp_webapp_meta)
|
65
|
+
File.delete(tmp_dep1_meta)
|
66
|
+
end
|
67
|
+
end
|
data/spec/load_ansible_spec.rb
CHANGED
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.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- volanja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/src/Rakefile
|
135
135
|
- lib/src/spec/spec_helper.rb
|
136
136
|
- spec/commands_spec.rb
|
137
|
+
- spec/dependency_spec.rb
|
137
138
|
- spec/dynamic_inventory_spec.rb
|
138
139
|
- spec/ec2_dynamic_inventory_spec.rb
|
139
140
|
- spec/inventory_parameters_spec.rb
|
@@ -167,6 +168,7 @@ summary: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Hos
|
|
167
168
|
by Ansible Configuration
|
168
169
|
test_files:
|
169
170
|
- spec/commands_spec.rb
|
171
|
+
- spec/dependency_spec.rb
|
170
172
|
- spec/dynamic_inventory_spec.rb
|
171
173
|
- spec/ec2_dynamic_inventory_spec.rb
|
172
174
|
- spec/inventory_parameters_spec.rb
|