diff options
| author | ckonstanski <ckonstanski@pippiandcarlos.com> | 2017-12-09 00:37:55 +0000 |
|---|---|---|
| committer | ckonstanski <ckonstanski@pippiandcarlos.com> | 2017-12-09 00:37:55 +0000 |
| commit | 2448c98206dda09bad00e16f635d7ec1c843bbd3 (patch) | |
| tree | 8153f7605cff5cc33b18135ffe4176e3089e5512 /inventory_json_unstable_db.rb | |
| parent | 37de0831718e5a4e54210462f501c97394803008 (diff) | |
autocommit Sat Dec 9 00:37:55 UTC 2017
Diffstat (limited to 'inventory_json_unstable_db.rb')
| -rwxr-xr-x | inventory_json_unstable_db.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/inventory_json_unstable_db.rb b/inventory_json_unstable_db.rb new file mode 100755 index 0000000..4a41f97 --- /dev/null +++ b/inventory_json_unstable_db.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby + +require "json" +require "yaml" + +def doit() + env_yaml_path = "#{File.dirname($0)}/conf/env.yaml" + if ! File.file?(env_yaml_path) + STDERR.puts "Unable to find env.yaml. Exiting." + exit(1) + end + environ = "" + ["unstable_db", "unstable", "develop_db", "develop", "stage_db", "stage", "master_db", "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_arr = [] + yml = YAML.load_file(env_yaml_path) + yml["globals"].each do |key, value| + globs[key] = value + end + 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_arr} + outobj["_meta"] = {"hostvars" => hostvars} + puts outobj.to_json +end + +doit() +exit(0) |
