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

Version Path
qb-0.1.55 roles/nrser.rb/library/vars.rb
qb-0.1.54 roles/nrser.rb/library/vars.rb
qb-0.1.53 roles/nrser.rb/library/vars.rb
qb-0.1.52 roles/nrser.rb/library/vars.rb
qb-0.1.51 roles/nrser.rb/library/vars.rb
qb-0.1.50 roles/nrser.rb/library/vars.rb
qb-0.1.49 roles/nrser.rb/library/vars.rb
qb-0.1.48 roles/nrser.rb/library/vars.rb
qb-0.1.47 roles/nrser.rb/library/vars.rb
qb-0.1.46 roles/nrser.rb/library/vars.rb
qb-0.1.45 roles/nrser.rb/library/vars.rb
qb-0.1.44 roles/nrser.rb/library/vars.rb
qb-0.1.43 roles/nrser.rb/library/vars.rb
qb-0.1.42 roles/nrser.rb/library/vars.rb
qb-0.1.41 roles/nrser.rb/library/vars.rb
qb-0.1.40 roles/nrser.rb/library/vars.rb
qb-0.1.39 roles/nrser.rb/library/vars.rb
qb-0.1.38 roles/nrser.rb/library/vars.rb
qb-0.1.37 roles/nrser.rb/library/vars.rb
qb-0.1.36 roles/nrser.rb/library/vars.rb