]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/allnodeinfo.rb
hmm, I could have sworn this was working earlier ...
[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         attributes.each do |a|
16           next if x[a].empty?
17         end
18         results << x
19       end
20     rescue LDAP::ResultError
21       raise Puppet::ParseError, "LDAP error"
22     rescue RuntimeError
23       raise Puppet::ParseError, "No data returned from search"
24     ensure
25       ldap.unbind
26     end
27     return(results)
28   end
29 end