skip entries that don't have all the attributes we're searching for
[mirror/dsa-puppet.git] / files / etc / puppet / lib / puppet / parser / functions / nodeinfo.rb
index db16133..d7f3dae 100644 (file)
@@ -21,7 +21,30 @@ module Puppet::Parser::Functions
       end
     end
 
-    ldap = LDAP::Conn.new('samosa.debian.org')
+    if yaml.has_key?('services')
+      yaml['services'].each_pair do |service, hostlist|
+        hostlist=[hostlist] unless hostlist.kind_of?(Array)
+        results[service] = hostlist.include?(host)
+      end
+    end
+
+    results['mail_port']      = ''
+    results['smarthost']      = ''
+    results['heavy_exim']     = ''
+    results['smarthost_port'] = 587
+    results['reservedaddrs']  = '0.0.0.0/8 : 127.0.0.0/8 : 10.0.0.0/8 : 169.254.0.0/16 : 172.16.0.0/12 : 192.0.0.0/17 : 192.168.0.0/16 : 224.0.0.0/4 : 240.0.0.0/5 : 248.0.0.0/5'
+
+    if yaml['host_settings'].kind_of?(Hash)
+      yaml['host_settings'].each_pair do |property, values|
+        if values.kind_of?(Hash)
+          results[property] = values[host] if values.has_key?(host)
+        elsif values.kind_of?(Array)
+          results[property] = "true" if values.include?(host)
+        end
+      end
+    end
+
+    ldap = LDAP::SSLConn.new('db.debian.org', 636)
 
     results['ldap'] = []
     filter = '(hostname=' + host +')'
@@ -30,10 +53,14 @@ module Puppet::Parser::Functions
         results['ldap'] << x
       end
     rescue LDAP::ResultError
+      raise Puppet::ParseError, "LDAP error"
     rescue RuntimeError
+      raise Puppet::ParseError, "No data returned from search"
     ensure
       ldap.unbind
     end
     return(results)
   end
 end
+
+# vim: set fdm=marker ts=2 sw=2 et: