Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created July 15, 2010 12:44
Show Gist options
  • Save ohadlevy/476882 to your computer and use it in GitHub Desktop.
Save ohadlevy/476882 to your computer and use it in GitHub Desktop.
diff --git a/extras/query/foreman.rb b/extras/query/foreman.rb
index dca1e25..703c0d0 100644
--- a/extras/query/foreman.rb
+++ b/extras/query/foreman.rb
@@ -1,13 +1,22 @@
require 'yaml'
-require 'net/http'
+require 'net/https'
+class NilClass; def closed?; true; end; end
# returns an array of hosts
# expects a hash with facts and classes - e.g.:
#{"fact"=>{"domain"=>"domain", "puppetversion"=>"0.24.4"}, "class" => ["common","my_special_class"], "state" => "all", "host
def gethosts(query = {})
- url="http://localhost:3000"
+ url="https://foreman"
begin
- result = YAML::load(Net::HTTP.get(URI.parse("#{url}/hosts/query?#{query.to_url}&format=yml")))
+ uri = URI.parse url
+ http = Net::HTTP.new(uri.host, uri.port)
+ if uri.scheme == 'https' then
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+ req = Net::HTTP::Get.new "/hosts/query?#{query.to_url}&format=yml"
+ response = http.request(req)
+ result = YAML::load response.body
result == "404 Not Found" ? nil : result
rescue Exception => e
raise e
@@ -41,4 +50,3 @@ class Hash
return (fact + klass + group).join("&")+"&#{state}&#{verbose}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment