Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created October 14, 2009 09:52
Show Gist options
  • Save ohadlevy/209931 to your computer and use it in GitHub Desktop.
Save ohadlevy/209931 to your computer and use it in GitHub Desktop.
require 'net/http'
# Query Foreman
module Puppet::Parser::Functions
newfunction(:foreman, :type => :rvalue) do |args|
#URL to query
host = "foreman"
url = "/query?"
query = []
args.each do |arg|
name, value = arg.split("=")
case name
when "fact" or "class"
query << "#{name}=#{value}"
when "verbose"
query << "verbose=yes" if value == "yes"
else
raise Puppet::ParseError, "Foreman: Invalid parameter #{name}"
end
end
begin
response = Net::HTTP.get host,url+query.join("&")
rescue Exception => e
raise Puppet::ParseError, "Failed to contact Foreman #{e}"
end
begin
hostlist = YAML::Load response
rescue Exception => e
raise Puppet::ParseError, "Failed to parse response from Foreman #{e}"
end
return response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment