class AnsibleModule
Private Class Methods
instance()
click to toggle source
# File lib/ansible_module.rb, line 48 def instance @instance ||= new(params) end
params()
click to toggle source
# File lib/ansible_module.rb, line 52 def params return @params if @params @params = ActiveSupport::HashWithIndifferentAccess.new File.open(ARGV[0]) do |fh| fh.read.shellsplit.each do |word| (key, value) = word.split('=', 2) @params[key] = value end end @params end
Public Instance Methods
main()
click to toggle source
# File lib/ansible_module.rb, line 11 def main raise "Not implemented." end
run()
click to toggle source
# File lib/ansible_module.rb, line 15 def run if valid? main else invalid_json end rescue StandardError => e fail_json(msg: "Failed: #{e.to_s}") end
Private Instance Methods
exit_json(hash)
click to toggle source
# File lib/ansible_module.rb, line 27 def exit_json(hash) hash = ActiveSupport::HashWithIndifferentAccess.new(hash) print JSON.dump(hash) exit 0 end
fail_json(hash)
click to toggle source
# File lib/ansible_module.rb, line 33 def fail_json(hash) hash = ActiveSupport::HashWithIndifferentAccess.new(hash) hash[:failed] = true hash[:msg] ||= "No error message." print JSON.dump(hash) exit 1 end
invalid_json()
click to toggle source
# File lib/ansible_module.rb, line 41 def invalid_json message = 'Invalid parameters: ' message += errors.full_messages.map { |m| "#{m}." }.join(' ') fail_json(msg: message) end