X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=files%2Fetc%2Fpuppet%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fnodeinfo.rb;h=2cdfab9a68d956010bfda534e9c18ab4266df9f1;hb=bca9104c33e9f202ebb7ca3c40daf8facac0f11c;hp=9f849ffb2cc9a12b6ddce515222e3d65c924d2b4;hpb=f3e377f781db5994054c1969b3639143a92f6a26;p=mirror%2Fdsa-puppet.git diff --git a/files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb b/files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb index 9f849ffb2..2cdfab9a6 100644 --- a/files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb +++ b/files/etc/puppet/lib/puppet/parser/functions/nodeinfo.rb @@ -3,71 +3,26 @@ module Puppet::Parser::Functions host = args[0] yamlfile = args[1] - parser.watch_file(yamlfile) - require 'ldap' - require 'yaml' + require '/etc/puppet/lib/puppet/parser/functions/ldapinfo.rb' - $KCODE = 'utf-8' + results = function_yamlinfo(host, yamlfile) + results['ldap'] = function_ldapinfo(host, '*') - yaml = YAML.load_file(yamlfile) - results = {} - - ['nameinfo', 'footer'].each do |detail| - if yaml.has_key?(detail) - if yaml[detail].has_key?(host) - results[detail] = yaml[detail][host] - end + results['misc'] = {} + fqdn = lookupvar('fqdn') + if fqdn and fqdn == host + v4ips = lookupvar('v4ips') + if v4ips + # find out if we are behind nat + v4addrs = v4ips.split(',') + intersection = v4addrs & results['ldap']['ipHostNumber'] + results['misc']['natted'] = intersection.empty? end end - if yaml.has_key?('services') - ['bugsmaster', 'qamaster', 'mailrelay', 'rtmaster', 'packagesmaster', 'packagesqamaster'].each do |service| - if yaml['services'].has_key?(service) - results[service] = host == yaml['services'][service] - end - end - end - - results['mail_port'] = '' - results['smarthost'] = '' - results['heavy_exim'] = '' - results['smarthost_port'] = 587 - 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' - - if yaml.has_key?('mail_port') and yaml['mail_port'].has_key?(host) - results['mail_port'] = yaml['mail_port'][host] - end - - if yaml.has_key?('need_smarthost') and yaml['need_smarthost'].include?(host) - results['smarthost'] = "mailout.debian.org" - end - - if yaml.has_key?('reservedaddrs') and yaml['reservedaddrs'].has_key?(host) - results['reservedaddrs'] = yaml['reservedaddrs'][host] - end - - if yaml.has_key?('heavy_exim') and yaml['heavy_exim'].include?(host) - results['heavy_exim'] = "true" - end - - if yaml.has_key?('apache2_defaultconfig') and yaml['apache2_defaultconfig'].include?(host) - results['apache2_defaultconfig'] = "true" - end - - ldap = LDAP::Conn.new('db.debian.org') - - results['ldap'] = [] - filter = '(hostname=' + host +')' - begin - ldap.search2('ou=hosts,dc=debian,dc=org', LDAP::LDAP_SCOPE_SUBTREE, filter) do |x| - results['ldap'] << x - end - rescue LDAP::ResultError - rescue RuntimeError - ensure - ldap.unbind - end return(results) end end + +# vim: set fdm=marker ts=2 sw=2 et: