]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/allnodeinfo.rb
I think it's better to raise an exception and die rather than silently
[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") do |x|
14         results << x
15       end
16     rescue LDAP::ResultError
17       raise Puppet::ParseError, "LDAP error"
18     rescue RuntimeError
19       raise Puppet::ParseError, "No data returned from search"
20     ensure
21       ldap.unbind
22     end
23     return(results)
24   end
25 end