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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/lib/ansible_spec/load_ansible.rb +38 -1
- data/lib/ansible_spec/version.rb +1 -1
- data/lib/src/Rakefile +6 -0
- data/lib/src/spec/spec_helper.rb +2 -1
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/.ansiblespec +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/dynamic_inventory.sh +43 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/all +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/database-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/develop-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/staging-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/site.yml +30 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/.ansiblespec +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/dynamic_inventory.sh +43 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/all +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/database-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/develop-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/staging-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/site.yml +30 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/.ansiblespec +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/dynamic_inventory.sh +43 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/all +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/database-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/develop-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/production-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging +5 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-application-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-database-servers +2 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/staging-web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/group_vars/web-servers +1 -0
- data/spec/case/get_variable/group_vars_hosts_childrens_env_stg/site.yml +30 -0
- data/spec/dynamic_inventory_hosts_childrens_spec.rb +304 -0
- data/spec/dynamic_inventory_spec.rb +9 -6
- data/spec/ec2_dynamic_inventory_spec.rb +4 -4
- data/spec/get_variable_hosts_childrens_spec.rb +322 -0
- data/spec/inventory_parameters_spec.rb +2 -2
- data/spec/load_ansible_spec.rb +185 -4
- metadata +120 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36492efa35f0617418b2c9c34a7916adc52e8dbd
|
4
|
+
data.tar.gz: 6f4df6208a073f20130d79890cecb3ab45bcea74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ff5843adbf7c13d4d4599631e5cdca4c8b4476fcdcc2f24e89ca6966dcf5fffb7ad3cf20b37f9242a4562850fea11dcaf578b0b2251941768cf8420b5bb7e66
|
7
|
+
data.tar.gz: f970aae2a33a607ac2e45b0ea7b0d3073d3b60049165c797448bab9c47a51986bf48d695baf004abbef03f6cd060c2fb5827376bbadc99a7c16a16fe0286fda9
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
- v0.2.13
|
2
|
+
- Merge [Dynamic Inventory use multiple hosts, lookup group children dependency group_vars.](https://github.com/volanja/ansible_spec/pull/73) by [guyon](https://github.com/guyon)
|
3
|
+
|
1
4
|
- v0.2.12
|
2
5
|
- Merge [Support deep merge for variable](https://github.com/volanja/ansible_spec/pull/72) by [okamototk](https://github.com/okamototk)
|
3
6
|
|
@@ -108,6 +108,10 @@ module AnsibleSpec
|
|
108
108
|
so, se, st = Open3.capture3(file_path)
|
109
109
|
dyn_inv = Oj.load(so.to_s)
|
110
110
|
|
111
|
+
res["hosts_childrens"] = dyn_inv.select do |property, value|
|
112
|
+
value.instance_of?(Hash) && value.has_key?("children")
|
113
|
+
end
|
114
|
+
|
111
115
|
if dyn_inv.key?('_meta')
|
112
116
|
# assume we have an ec2.py created dynamic inventory
|
113
117
|
dyn_inv = dyn_inv.tap{ |h| h.delete("_meta") }
|
@@ -332,11 +336,25 @@ module AnsibleSpec
|
|
332
336
|
hosts = load_targets(inventoryfile)
|
333
337
|
properties = load_playbook(playbook)
|
334
338
|
properties.each do |var|
|
339
|
+
var["hosts_childrens"] = hosts["hosts_childrens"]
|
335
340
|
var["group"] = var["hosts"]
|
336
341
|
if var["hosts"].to_s == "all"
|
337
342
|
var["hosts"] = hosts.values.flatten
|
338
343
|
elsif hosts.has_key?("#{var["hosts"]}")
|
339
344
|
var["hosts"] = hosts["#{var["hosts"]}"]
|
345
|
+
elsif var["hosts"].instance_of?(Array)
|
346
|
+
tmp_host = var["hosts"]
|
347
|
+
var["hosts"] = []
|
348
|
+
tmp_host.each do |v|
|
349
|
+
if hosts.has_key?("#{v}")
|
350
|
+
hosts["#{v}"].map {|target_server| target_server["hosts"] = v}
|
351
|
+
var["hosts"].concat hosts["#{v}"]
|
352
|
+
end
|
353
|
+
end
|
354
|
+
if var["hosts"].size == 0
|
355
|
+
properties = properties.compact.reject{|e| e["hosts"].length == 0}
|
356
|
+
#puts "#{var["name"]} roles no hosts matched for #{var["hosts"]}"
|
357
|
+
end
|
340
358
|
else
|
341
359
|
puts "no hosts matched for #{var["hosts"]}"
|
342
360
|
var["hosts"] = []
|
@@ -345,7 +363,14 @@ module AnsibleSpec
|
|
345
363
|
return properties
|
346
364
|
end
|
347
365
|
|
348
|
-
def self.
|
366
|
+
def self.find_group_vars_file(hosts_childrens, hosts)
|
367
|
+
target_host = hosts_childrens.select { |key, value|
|
368
|
+
value["children"].include?(hosts)
|
369
|
+
}
|
370
|
+
target_host.keys[0]
|
371
|
+
end
|
372
|
+
|
373
|
+
def self.get_variables(host, group_idx, hosts=nil)
|
349
374
|
vars = {}
|
350
375
|
p = self.get_properties
|
351
376
|
|
@@ -375,6 +400,18 @@ module AnsibleSpec
|
|
375
400
|
vars = load_vars_file(vars ,"roles/#{role}/vars/main.yml")
|
376
401
|
end
|
377
402
|
|
403
|
+
# multiple host and children dependencies group vars
|
404
|
+
unless hosts.nil?
|
405
|
+
hosts_childrens = p[group_idx]["hosts_childrens"]
|
406
|
+
next_find_target = hosts
|
407
|
+
while(!next_find_target.nil? && hosts_childrens.size > 0)
|
408
|
+
vars = load_vars_file(vars ,"group_vars/#{next_find_target}", true)
|
409
|
+
group_vars_file = find_group_vars_file(hosts_childrens,next_find_target)
|
410
|
+
next_find_target = group_vars_file
|
411
|
+
hosts_childrens.delete(group_vars_file)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
378
415
|
return vars
|
379
416
|
|
380
417
|
end
|
data/lib/ansible_spec/version.rb
CHANGED
data/lib/src/Rakefile
CHANGED
@@ -7,12 +7,18 @@ properties = AnsibleSpec.get_properties
|
|
7
7
|
# {"name"=>"Ansible-Sample-TDD", "hosts"=>["192.168.0.103","192.168.0.103"], "user"=>"root", "roles"=>["nginx", "mariadb"]}
|
8
8
|
# {"name"=>"Ansible-Sample-TDD", "hosts"=>[{"name" => "192.168.0.103:22","uri"=>"192.168.0.103","port"=>22, "private_key"=> "~/.ssh/id_rsa"}], "user"=>"root", "roles"=>["nginx", "mariadb"]}
|
9
9
|
|
10
|
+
desc "Run serverspec to all test"
|
11
|
+
task :all => "serverspec:all"
|
12
|
+
|
10
13
|
namespace :serverspec do
|
14
|
+
task :all => properties.map {|v| 'serverspec:' + v["name"] }
|
15
|
+
properties = properties.compact.reject{|e| e["hosts"].length == 0}
|
11
16
|
properties.each_with_index.map do |property, index|
|
12
17
|
property["hosts"].each do |host|
|
13
18
|
desc "Run serverspec for #{property["name"]}"
|
14
19
|
RSpec::Core::RakeTask.new(property["name"].to_sym) do |t|
|
15
20
|
puts "Run serverspec for #{property["name"]} to #{host}"
|
21
|
+
ENV['TARGET_HOSTS'] = host["hosts"]
|
16
22
|
ENV['TARGET_HOST'] = host["uri"]
|
17
23
|
ENV['TARGET_PORT'] = host["port"].to_s
|
18
24
|
ENV['TARGET_GROUP_INDEX'] = index.to_s
|
data/lib/src/spec/spec_helper.rb
CHANGED
@@ -7,9 +7,10 @@ require 'winrm'
|
|
7
7
|
# Set ansible variables to serverspec property
|
8
8
|
#
|
9
9
|
host = ENV['TARGET_HOST']
|
10
|
+
hosts = ENV["TARGET_HOSTS"]
|
10
11
|
|
11
12
|
group_idx = ENV['TARGET_GROUP_INDEX'].to_i
|
12
|
-
vars = AnsibleSpec.get_variables(host, group_idx)
|
13
|
+
vars = AnsibleSpec.get_variables(host, group_idx,hosts)
|
13
14
|
set_property vars
|
14
15
|
|
15
16
|
connection = ENV['TARGET_CONNECTION']
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
cat << EOS
|
3
|
+
{
|
4
|
+
"database-servers": {
|
5
|
+
"hosts": [
|
6
|
+
"10.0.0.4"
|
7
|
+
]
|
8
|
+
},
|
9
|
+
"application-servers": {
|
10
|
+
"hosts": [
|
11
|
+
"10.0.0.2",
|
12
|
+
"10.0.0.3"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"web-servers": {
|
16
|
+
"hosts": [
|
17
|
+
"10.0.0.1"
|
18
|
+
]
|
19
|
+
},
|
20
|
+
"develop-database-servers": {
|
21
|
+
"children": [
|
22
|
+
"database-servers"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"develop-application-servers": {
|
26
|
+
"children": [
|
27
|
+
"application-servers"
|
28
|
+
]
|
29
|
+
},
|
30
|
+
"develop-web-servers": {
|
31
|
+
"children": [
|
32
|
+
"web-servers"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
"develop": {
|
36
|
+
"children": [
|
37
|
+
"develop-web-servers",
|
38
|
+
"develop-application-servers",
|
39
|
+
"develop-database-servers"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
EOS
|
@@ -0,0 +1 @@
|
|
1
|
+
all_variable: "all!!"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "application_logs.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "database_logs.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_92"
|
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "develop_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_45"
|
data/spec/case/get_variable/group_vars_hosts_childrens_env_dev/group_vars/production-web-servers
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "production_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_66"
|
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "staging_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "web_logs.conf"
|
@@ -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,43 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
cat << EOS
|
3
|
+
{
|
4
|
+
"database-servers": {
|
5
|
+
"hosts": [
|
6
|
+
"10.0.0.4"
|
7
|
+
]
|
8
|
+
},
|
9
|
+
"application-servers": {
|
10
|
+
"hosts": [
|
11
|
+
"10.0.0.2",
|
12
|
+
"10.0.0.3"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"web-servers": {
|
16
|
+
"hosts": [
|
17
|
+
"10.0.0.1"
|
18
|
+
]
|
19
|
+
},
|
20
|
+
"production-database-servers": {
|
21
|
+
"children": [
|
22
|
+
"database-servers"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"production-application-servers": {
|
26
|
+
"children": [
|
27
|
+
"application-servers"
|
28
|
+
]
|
29
|
+
},
|
30
|
+
"production-web-servers": {
|
31
|
+
"children": [
|
32
|
+
"web-servers"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
"production": {
|
36
|
+
"children": [
|
37
|
+
"production-web-servers",
|
38
|
+
"production-application-servers",
|
39
|
+
"production-database-servers"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
EOS
|
@@ -0,0 +1 @@
|
|
1
|
+
all_variable: "all!!"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "application_logs.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "database_logs.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_92"
|
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "develop_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_45"
|
data/spec/case/get_variable/group_vars_hosts_childrens_env_prd/group_vars/production-web-servers
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "production_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
java_version: "1.8.0_66"
|
@@ -0,0 +1 @@
|
|
1
|
+
nginx_conf_file: "staging_nginx.conf"
|
@@ -0,0 +1 @@
|
|
1
|
+
logs_conf_file: "web_logs.conf"
|
@@ -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,43 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
cat << EOS
|
3
|
+
{
|
4
|
+
"database-servers": {
|
5
|
+
"hosts": [
|
6
|
+
"10.0.0.4"
|
7
|
+
]
|
8
|
+
},
|
9
|
+
"application-servers": {
|
10
|
+
"hosts": [
|
11
|
+
"10.0.0.2",
|
12
|
+
"10.0.0.3"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"web-servers": {
|
16
|
+
"hosts": [
|
17
|
+
"10.0.0.1"
|
18
|
+
]
|
19
|
+
},
|
20
|
+
"staging-database-servers": {
|
21
|
+
"children": [
|
22
|
+
"database-servers"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"staging-application-servers": {
|
26
|
+
"children": [
|
27
|
+
"application-servers"
|
28
|
+
]
|
29
|
+
},
|
30
|
+
"staging-web-servers": {
|
31
|
+
"children": [
|
32
|
+
"web-servers"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
"staging": {
|
36
|
+
"children": [
|
37
|
+
"staging-web-servers",
|
38
|
+
"staging-application-servers",
|
39
|
+
"staging-database-servers"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
EOS
|