]> git.donarmstrong.com Git - dsa-puppet.git/blob - files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb
d8af932a9c5800571d7330bdbfd9516d6e925bcf
[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       yaml['services'].each_pair do |service, hostlist|
26         hostlist=[hostlist] unless hostlist.kind_of?(Array)
27         results[service] = hostlist.include?(host)
28       end
29     end
30
31     results['mail_port']      = ''
32     results['smarthost']      = ''
33     results['heavy_exim']     = ''
34     results['smarthost_port'] = 587
35     results['reservedaddrs']  = '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'
36
37     if yaml['host_settings'].kind_of?(Hash)
38       yaml['host_settings'].each_pair do |property, values|
39         if values.kind_of?(Hash)
40           results[property] = values[host] if values.has_key?(host)
41         elsif values.kind_of?(Array)
42           results[property] = "true" if values.include?(host)
43         end
44       end
45     end
46
47     results['ldap'] = function_ldapinfo(host, '*')
48   end
49 end
50
51 # vim: set fdm=marker ts=2 sw=2 et: