From: Peter Palfrader Date: Wed, 2 Mar 2011 11:58:00 +0000 (+0100) Subject: In allnodeinfo distinguish between mandatory and required attributes X-Git-Url: https://git.donarmstrong.com/?p=dsa-puppet.git;a=commitdiff_plain;h=fbdfced4d644a867a1913ff13e94fb6851bb8442 In allnodeinfo distinguish between mandatory and required attributes --- diff --git a/manifests/site.pp b/manifests/site.pp index 5dfeef0a..920ebfa7 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -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}") diff --git a/modules/puppetmaster/lib/puppet/parser/functions/allnodeinfo.rb b/modules/puppetmaster/lib/puppet/parser/functions/allnodeinfo.rb index 47450d55..85a0c749 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/allnodeinfo.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/allnodeinfo.rb @@ -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: diff --git a/modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb b/modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb index 3a687224..489970e6 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb @@ -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