]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb
Pull the information out of the yaml file so we don't have to restart
[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     if yaml.has_key?('services')
25       ['bugsmaster', 'qamaster', 'mailrelay', 'rtmaster', 'packagesmaster'].each do |service|
26         if yaml['services'].has_key?(service)
27           results[service] = host == yaml['services'][service]
28         end
29       end
30     end
31
32     if yaml.has_key?('need_smarthost') and yaml['need_smarthost'].include?(host)
33       results['smarthost']      = "mailout.debian.org"
34       results['smarthost_port'] = 587
35     else
36       results['smarthost']      = ''
37       results['smarthost_port'] = ''
38     end
39
40     results['reservedaddrs'] = case host
41       when "ball.debian.org"
42         '0.0.0.0/8 : 127.0.0.0/8 : 169.254.0.0/16 : 172.16.0.0/12 : 192.0.0.0/17 : 192.168.0.0/16 : 224.0.0.0/4 : 240.0.0.0/5 : 248.0.0.0/5'
43       else
44         '0.0.0.0/8 : 127.0.0.0/8 : 10.0.0.0/8 : 169.254.0.0/16 : 172.16.0.0/12 : 192.0.0.0/17 : 192.168.0.0/16 : 224.0.0.0/4 : 240.0.0.0/5 : 248.0.0.0/5'
45     end
46
47     ldap = LDAP::Conn.new('db.debian.org')
48
49     results['ldap'] = []
50     filter = '(hostname=' + host +')'
51     begin
52       ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter) do |x|
53         results['ldap'] << x
54       end
55     rescue LDAP::ResultError
56     rescue RuntimeError
57     ensure
58       ldap.unbind
59     end
60     return(results)
61   end
62 end