]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/allnodeinfo.rb
use weaselism: it has the benefit of possibly working
[dsa-puppet.git] / files / etc / puppet / lib / puppet / parser / functions / allnodeinfo.rb
1 module Puppet::Parser::Functions
2   newfunction(:allnodeinfo, :type => :rvalue) do |attributes|
3
4     unless attributes.include?('hostname')
5       attributes << 'hostname'
6     end
7
8     ldap = LDAP::SSLConn.new('db.debian.org', 636)
9
10     results = []
11     filter = '(hostname=*)'
12     begin
13       ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter, attrs=attributes, false, 0, 0, s_attr="hostname").each do |x|
14         # If a returned value doesn't have all the attributes we're searching for, skip
15         # We'll skip if the array is empty, but we also seem to get back a nil object for empty attributes sometimes
16         next if attributes.any?{ |a|  not x[a] or x[a].empty? }
17         results << x
18       end
19     rescue LDAP::ResultError
20       raise Puppet::ParseError, "LDAP error"
21     rescue RuntimeError
22       raise Puppet::ParseError, "No data returned from search"
23     ensure
24       ldap.unbind
25     end
26     return(results)
27   end
28 end