1 module Puppet::Parser::Functions
2 newfunction(:allnodeinfo, :type => :rvalue) do |attributes|
4 unless attributes.include?('hostname')
5 attributes << 'hostname'
8 ldap = LDAP::SSLConn.new('db.debian.org', 636)
11 filter = '(hostname=*)'
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? }
19 rescue LDAP::ResultError
20 raise Puppet::ParseError, "LDAP error"
22 raise Puppet::ParseError, "No data returned from search"