summaryrefslogtreecommitdiff
path: root/salt/openbook/ansible/files/inventory_json.rb
diff options
context:
space:
mode:
Diffstat (limited to 'salt/openbook/ansible/files/inventory_json.rb')
-rw-r--r--salt/openbook/ansible/files/inventory_json.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/salt/openbook/ansible/files/inventory_json.rb b/salt/openbook/ansible/files/inventory_json.rb
index 8a01004..e4a5938 100644
--- a/salt/openbook/ansible/files/inventory_json.rb
+++ b/salt/openbook/ansible/files/inventory_json.rb
@@ -9,23 +9,38 @@ def doit()
STDERR.puts "Unable to find env.yaml. Exiting."
exit(1)
end
+ environ = ""
+ ["unstable", "develop", "stage", "master"].each do |env|
+ if File.basename($0).include?(env)
+ environ = env
+ break
+ end
+ end
+ if environ == ""
+ STDERR.puts "Unable to determine environment. Exiting."
+ exit(1)
+ end
globs = {}
hostvars = {}
outobj = {}
- hosts = []
+ hosts_arr = []
yml = YAML.load_file(env_yaml_path)
yml["globals"].each do |key, value|
globs[key] = value
end
- yml["hosts"].each do |h|
- h.each do |host, attributes|
- hosts.push(host)
- attributes.each do |attribute, value|
- hostvars[host] = globs.merge(attributes)
+ yml["environments"].each do |ee|
+ ee.each do |e, hosts|
+ if e == environ
+ hosts.each do |host_hash|
+ host_hash.each do |host, attributes|
+ hosts_arr.push(host)
+ hostvars[host] = globs.merge(attributes)
+ end
+ end
end
end
end
- outobj["target"] = {"hosts" => hosts}
+ outobj["target"] = {"hosts" => hosts_arr}
outobj["_meta"] = {"hostvars" => hostvars}
puts outobj.to_json
end