Created
October 14, 2009 09:52
-
-
Save ohadlevy/209931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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