Sha256: b0d2df9a1613b4069cf9e6cb387bd720087c641d7774ea94abde24f9578cbdb6
Contents?: true
Size: 1.07 KB
Versions: 38
Compression:
Stored size: 1.07 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 print JSON.dump({ 'failed' => true, 'msg' => e.message, # 'input' => input, # 'args' => args, # 'ARGV' => ARGV, # 'ruby' => RUBY_VERSION, }) end end main if __FILE__ == $0
Version data entries
38 entries across 38 versions & 1 rubygems