]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/ldapinfo.rb
Always remove acpi packages from jessie hosts
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / ldapinfo.rb
1 module Puppet::Parser::Functions
2   newfunction(:ldapinfo, :type => :rvalue) do |attributes|
3
4     host = attributes.shift
5
6     unless attributes.include?("*") or attributes.include?('hostname')
7       attributes << 'hostname'
8     end
9
10     require 'ldap'
11     ldap = LDAP::SSLConn.new('db.debian.org', 636)
12
13     results = {}
14     filter = '(hostname=' + host + ')'
15     begin
16       ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter, attrs=attributes, false, 0, 0, s_attr="hostname").each do |x|
17         results[x['hostname'][0]] = 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     if host == '*'
27       return(results)
28     else
29       return(results[host])
30     end
31   end
32 end