diff options
| author | ckonstanski <ckonstanski@pippiandcarlos.com> | 2017-10-24 18:27:27 -0600 |
|---|---|---|
| committer | ckonstanski <ckonstanski@pippiandcarlos.com> | 2017-10-24 18:27:27 -0600 |
| commit | 0493747f5d1b30008b4170b3d48080abfa224700 (patch) | |
| tree | 4ee87ddb639f30a47e95861409a1b9d71d183e07 /salt/openbook/ansible/files/inventory_json.rb | |
| parent | dd48453e079d5c93f7cf0af59843bd7d4180e186 (diff) | |
make it work for all 4 git branches
Diffstat (limited to 'salt/openbook/ansible/files/inventory_json.rb')
| -rw-r--r-- | salt/openbook/ansible/files/inventory_json.rb | 29 |
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 |
