Sha256: 75558d9406224c126e3798e51916058b65ceafde7fdee167346ecd6ce25bc414
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 KB
Contents
#!/usr/bin/env ruby # WANT_JSON # ^ i think this is something telling ansible to provide JSON args? require 'json' require 'shellwords' require 'pp' def namespace prefix, hash Hash[ hash.map {|key, value| ["#{ prefix }_#{ key }", value] } ] end def main input = nil args = nil changed = false begin input = File.read ARGV[0] args = JSON.load input b = binding ['bind', 'vars'].each do |key| if args.key? key args[key].each {|k, v| b.local_variable_set k, v } end end result = b.eval args['src'] if result.is_a? Hash result = namespace(args['namespace'], result) if args['namespace'] else result = {'result' => result} end print JSON.dump({ 'changed' => changed, 'ansible_facts' => result, }) rescue Exception => e raise e print JSON.dump({ 'failed' => true, 'msg' => e, # 'input' => input, # 'args' => args, # 'ARGV' => ARGV, # 'ruby' => RUBY_VERSION, }) end end main if __FILE__ == $0
Version data entries
7 entries across 7 versions & 1 rubygems