1 module Puppet::Parser::Functions
2 newfunction(:nodeinfo, :type => :rvalue) do |args|
7 require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb'
8 require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb'
10 nodeinfo = function_yamlinfo(host, yamlfile)
11 nodeinfo['ldap'] = function_ldapinfo(host, '*')
12 unless nodeinfo['ldap']['ipHostNumber']
13 raise Puppet::ParseError, "Host #{host} does not have ipHostNumber values in ldap"
15 nodeinfo['hoster'] = function_whohosts(nodeinfo['ldap']['ipHostNumber'], "/etc/puppet/modules/debian-org/misc/hoster.yaml")
16 nodeinfo['buildd'] = (nodeinfo['ldap']['purpose'].respond_to?('include?') && nodeinfo['ldap']['purpose'].include?('buildd'))
18 if lookupvar('::mta') == 'exim4'
19 unless nodeinfo['heavy_exim']
20 nodeinfo['smarthost'] = 'mailout.debian.org'
25 fqdn = lookupvar('::fqdn')
26 if fqdn and fqdn == host
27 v4ips = lookupvar('::v4ips')
28 if v4ips and v4ips.to_s != "" and v4ips.to_s != 'undefined'
29 nodeinfo['misc']['v4addrs'] = v4ips.split(',')
31 # find out if we are behind nat
32 intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
33 nodeinfo['misc']['natted'] = intersection.empty?
36 v6ips = lookupvar('::v6ips')
37 if v6ips and v6ips.to_s != "" and v6ips.to_s != 'undefined'
38 nodeinfo['misc']['v6addrs'] = v6ips.split(',')
42 ns = function_hiera('nameservers')
43 allow_dns_q = function_hiera('allow_dns_query')
45 # no nameservers known for this hoster
46 nodeinfo['misc']['resolver-recursive'] = true
48 if not allow_dns_q.empty?
49 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}."
51 elsif (nodeinfo['misc']['v4addrs'] and (ns & nodeinfo['misc']['v4addrs']).size > 0) or
52 (nodeinfo['misc']['v6addrs'] and (ns & nodeinfo['misc']['v6addrs']).size > 0)
53 # this host is listed as a nameserver at this location
54 nodeinfo['misc']['resolver-recursive'] = true
57 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"
60 nodeinfo['misc']['resolver-recursive'] = false
65 raise Puppet::ParseError, "Error in nodeinfo for node #{host}, yamlfile #{yamlfile}: #{e.message}\n#{e.backtrace}"
70 # vim: set fdm=marker ts=2 sw=2 et: