diff options
Diffstat (limited to 'salt/openbook/ansible/files/inventory_json.rb')
| -rw-r--r-- | salt/openbook/ansible/files/inventory_json.rb | 34 |
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) |
