#!/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)