1 module Puppet::Parser::Functions
2 newfunction(:nodeinfo, :type => :rvalue) do |args|
6 parser.watch_file(yamlfile)
13 yaml = YAML.load_file(yamlfile)
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]
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)
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'
37 if yaml.has_key?('mail_port') and yaml['mail_port'].has_key?(host)
38 results['mail_port'] = yaml['mail_port'][host]
41 if yaml.has_key?('need_smarthost') and yaml['need_smarthost'].include?(host)
42 results['smarthost'] = "mailout.debian.org"
45 if yaml.has_key?('reservedaddrs') and yaml['reservedaddrs'].has_key?(host)
46 results['reservedaddrs'] = yaml['reservedaddrs'][host]
49 if yaml.has_key?('heavy_exim') and yaml['heavy_exim'].include?(host)
50 results['heavy_exim'] = "true"
53 if yaml.has_key?('apache2_defaultconfig') and yaml['apache2_defaultconfig'].include?(host)
54 results['apache2_defaultconfig'] = "true"
57 ldap = LDAP::Conn.new('db.debian.org')
60 filter = '(hostname=' + host +')'
62 ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter) do |x|
65 rescue LDAP::ResultError
74 # vim: set fdm=marker ts=2 sw=2 et: