X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fnodeinfo.rb;h=cfbaa9c4ce775175c9b5093c53a3c44ab08aaddb;hb=b41bbe0bcc0ca74548ff8e99c3014452a7dc64f2;hp=f08405080e528d649bd3129c50a8f13467049ff4;hpb=5c56891f20ce485f48ccbd9221b2f35e9d423ad1;p=dsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb b/modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb index f0840508..cfbaa9c4 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb @@ -1,38 +1,70 @@ module Puppet::Parser::Functions newfunction(:nodeinfo, :type => :rvalue) do |args| - host = args[0] yamlfile = args[1] + begin - require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb' - require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb' + require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb' + require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb' - results = function_yamlinfo(host, yamlfile) - results['ldap'] = function_ldapinfo(host, '*') - unless results['ldap']['ipHostNumber'] - raise Puppet::ParseError, "Host #{host} does not have ipHostNumber values in ldap" - end - results['hoster'] = function_whohosts(results['ldap']['ipHostNumber'], "/etc/puppet/modules/debian-org/misc/hoster.yaml") - - results['misc'] = {} - fqdn = lookupvar('fqdn') - if fqdn and fqdn == host - v4ips = lookupvar('v4ips') - if v4ips - results['misc']['v4addrs'] = v4ips.split(',') - - # find out if we are behind nat - intersection = results['misc']['v4addrs'] & results['ldap']['ipHostNumber'] - results['misc']['natted'] = intersection.empty? + nodeinfo = function_yamlinfo([host, yamlfile]) + nodeinfo['ldap'] = function_ldapinfo([host, '*']) + unless nodeinfo['ldap']['ipHostNumber'] + raise Puppet::ParseError, "Host #{host} does not have ipHostNumber values in ldap" end + nodeinfo['hoster'] = function_whohosts([nodeinfo['ldap']['ipHostNumber'], "/etc/puppet/modules/debian-org/misc/hoster.yaml"]) + nodeinfo['buildd'] = (nodeinfo['ldap']['purpose'].respond_to?('include?') && nodeinfo['ldap']['purpose'].include?('buildd')) + nodeinfo['porterbox'] = (nodeinfo['ldap']['purpose'].respond_to?('include?') && nodeinfo['ldap']['purpose'].include?('porterbox')) - v6ips = lookupvar('v6ips') - if v6ips and v6ips != "no" - results['misc']['v6addrs'] = v6ips.split(',') + if lookupvar('::mta') == 'exim4' + unless nodeinfo['heavy_exim'] + nodeinfo['smarthost'] = 'mailout.debian.org' + end end - end - return(results) + nodeinfo['misc'] = {} + fqdn = lookupvar('::fqdn') + if fqdn and fqdn == host + v4ips = lookupvar('::v4ips') + if v4ips and v4ips.to_s != "" and v4ips.to_s != 'undefined' + nodeinfo['misc']['v4addrs'] = v4ips.split(',') + + # find out if we are behind nat + intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber'] + nodeinfo['misc']['natted'] = intersection.empty? + end + + v6ips = lookupvar('::v6ips') + if v6ips and v6ips.to_s != "" and v6ips.to_s != 'undefined' + nodeinfo['misc']['v6addrs'] = v6ips.split(',') + end + end + + ns = function_hiera(['nameservers']) + allow_dns_q = function_hiera(['allow_dns_query']) + if ns.empty? + # no nameservers known for this hoster + nodeinfo['misc']['resolver-recursive'] = true + + if not allow_dns_q.empty? + raise Puppet::ParseError, "No nameservers listed for #{nodeinfo['hoster']['name']} yet we should answer somebody's queries? That makes no sense. allow_dns_q: #{allow_dns_q}." + end + elsif (nodeinfo['misc']['v4addrs'] and (ns & nodeinfo['misc']['v4addrs']).size > 0) or + (nodeinfo['misc']['v6addrs'] and (ns & nodeinfo['misc']['v6addrs']).size > 0) + # this host is listed as a nameserver at this location + nodeinfo['misc']['resolver-recursive'] = true + + if allow_dns_q.empty? + raise Puppet::ParseError, "Host #{host} is listed as a nameserver for #{nodeinfo['hoster']['name']} but no allow_dns_query networks are defined for this location" + end + else + nodeinfo['misc']['resolver-recursive'] = false + end + + return(nodeinfo) + rescue => e + raise Puppet::ParseError, "Error in nodeinfo for node #{host}, yamlfile #{yamlfile}: #{e.message}\n#{e.backtrace}" + end end end