]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
In allnodeinfo distinguish between mandatory and required attributes
authorPeter Palfrader <peter@palfrader.org>
Wed, 2 Mar 2011 11:58:00 +0000 (12:58 +0100)
committerPeter Palfrader <peter@palfrader.org>
Wed, 2 Mar 2011 11:58:00 +0000 (12:58 +0100)
manifests/site.pp
modules/puppetmaster/lib/puppet/parser/functions/allnodeinfo.rb
modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb

index 5dfeef0a8e1d2be950b2009ed16b044d5141780f..920ebfa77ec441ffed3bda5a17c69ef88a88ff1e 100644 (file)
@@ -17,7 +17,7 @@ node default {
     $localinfo = yamlinfo('*', "/etc/puppet/modules/debian-org/misc/local.yaml")
     $nodeinfo  = nodeinfo($fqdn, "/etc/puppet/modules/debian-org/misc/local.yaml")
     $hosterinfo = whohosts($nodeinfo, "/etc/puppet/modules/debian-org/misc/hoster.yaml")
-    $allnodeinfo = allnodeinfo("sshRSAHostKey", "ipHostNumber", "purpose")
+    $allnodeinfo = allnodeinfo(["sshRSAHostKey", "ipHostNumber"], ["purpose"])
     $mxinfo    = allnodeinfo("mXRecord")
     notice("hoster for ${fqdn} is ${hosterinfo}")
 
index 47450d559e65f9ab7670febcdef26cf4b25114ed..85a0c749b39c9b59957a6f298a7b5a2cf0153933 100644 (file)
@@ -1,6 +1,20 @@
 module Puppet::Parser::Functions
-  newfunction(:allnodeinfo, :type => :rvalue) do |attributes|
-    attributes.unshift('*')
-    return (function_ldapinfo(attributes))
+  newfunction(:allnodeinfo, :type => :rvalue) do |args|
+    required = args.shift
+    optional = args.shift
+
+    allhosts = function_ldapinfo('*', required+optional )
+    res = {}
+    allhosts.each_pair do |hostname, host|
+        # If a returned value doesn't have all the attributes we're searching for, skip
+        # We'll skip if the array is empty, but we also seem to get back a nil object for empty attributes sometimes
+        next if required.any?{ |a| not host[a] or host[a].empty? }
+        res[hostname] = host
+    end
+
+    return res
   end
 end
+# vim:set et:
+# vim:set sts=2 ts=2:
+# vim:set shiftwidth=2:
index 3a687224dd5a5fa71173fa288ff6ba8b8292fb0a..489970e63c6ea162f033899defcea432c1bf4fa1 100644 (file)
@@ -14,11 +14,6 @@ module Puppet::Parser::Functions
     filter = '(hostname=' + host + ')'
     begin
       ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter, attrs=attributes, false, 0, 0, s_attr="hostname").each do |x|
-        # If a returned value doesn't have all the attributes we're searching for, skip
-        # We'll skip if the array is empty, but we also seem to get back a nil object for empty attributes sometimes
-        unless attributes.include?("*")
-          next if attributes.any?{ |a|  not x[a] or x[a].empty? }
-        end
         results[x['hostname'][0]] = x
       end
     rescue LDAP::ResultError