]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb
We want to talk to LDAP on db, not samosa
[dsa-puppet.git] / files / etc / puppet / lib / puppet / parser / functions / nodeinfo.rb
1 module Puppet::Parser::Functions
2   newfunction(:nodeinfo, :type => :rvalue) do |args|
3
4     host = args[0]
5     yamlfile = args[1]
6     parser.watch_file(yamlfile)
7
8     require 'ldap'
9     require 'yaml'
10
11     $KCODE = 'utf-8'
12
13     yaml = YAML.load_file(yamlfile)
14     results = {}
15
16     ['nameinfo', 'footer'].each do |detail|
17       if yaml.has_key?(detail)
18         if yaml[detail].has_key?(host)
19           results[detail] = yaml[detail][host]
20         end
21       end
22     end
23
24     ldap = LDAP::Conn.new('db.debian.org')
25
26     results['ldap'] = []
27     filter = '(hostname=' + host +')'
28     begin
29       ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter) do |x|
30         results['ldap'] << x
31       end
32     rescue LDAP::ResultError
33     rescue RuntimeError
34     ensure
35       ldap.unbind
36     end
37     return(results)
38   end
39 end