summaryrefslogtreecommitdiff
path: root/salt/openbook/ansible/files/inventory_json.rb
diff options
context:
space:
mode:
authorCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-08-30 13:09:56 -0600
committerCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-08-30 13:09:56 -0600
commit649f0dd9c5ca586d8b637400dd19c0c4059447d6 (patch)
tree5ccc992a3aa5de1bcb510911dfdb21e6a54bd197 /salt/openbook/ansible/files/inventory_json.rb
initial commit
Diffstat (limited to 'salt/openbook/ansible/files/inventory_json.rb')
-rw-r--r--salt/openbook/ansible/files/inventory_json.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/salt/openbook/ansible/files/inventory_json.rb b/salt/openbook/ansible/files/inventory_json.rb
new file mode 100644
index 0000000..8a01004
--- /dev/null
+++ b/salt/openbook/ansible/files/inventory_json.rb
@@ -0,0 +1,34 @@
+#!/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
+ globs = {}
+ hostvars = {}
+ outobj = {}
+ hosts = []
+ 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)
+ end
+ end
+ end
+ outobj["target"] = {"hosts" => hosts}
+ outobj["_meta"] = {"hostvars" => hostvars}
+ puts outobj.to_json
+end
+
+doit()
+exit(0)