]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb
303dfd21392685b4a7fdb9af3ba08e3de6762686
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / nodeinfo.rb
1 module Puppet::Parser::Functions
2   newfunction(:nodeinfo, :type => :rvalue) do |args|
3     host = args[0]
4     yamlfile = args[1]
5     begin
6
7       require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb'
8       require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb'
9
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"
14       end
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'))
17
18       if lookupvar('::mta') == 'exim4'
19         unless nodeinfo['heavy_exim']
20           nodeinfo['smarthost'] = 'mailout.debian.org'
21         end
22       end
23
24       nodeinfo['misc'] = {}
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(',')
30
31           # find out if we are behind nat
32           intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
33           nodeinfo['misc']['natted'] = intersection.empty?
34         end
35
36         v6ips = lookupvar('::v6ips')
37         if v6ips and v6ips.to_s != "" and v6ips.to_s != 'undefined'
38           nodeinfo['misc']['v6addrs'] = v6ips.split(',')
39         end
40       end
41
42       ns = function_hiera('nameservers')
43       if ns.empty?
44         # no nameservers known for this hoster
45         nodeinfo['misc']['resolver-recursive'] = true
46
47         if nodeinfo['hoster']['allow_dns_query']
48           raise Puppet::ParseError, "No nameservers listed for #{nodeinfo['hoster']['name']} yet we should answer somebody's queries?  That makes no sense."
49         end
50       elsif (nodeinfo['misc']['v4addrs'] and (ns & nodeinfo['misc']['v4addrs']).size > 0) or
51             (nodeinfo['misc']['v6addrs'] and (ns & nodeinfo['misc']['v6addrs']).size > 0)
52         # this host is listed as a nameserver at this location
53         nodeinfo['misc']['resolver-recursive'] = true
54
55         if not nodeinfo['hoster']['allow_dns_query'] or nodeinfo['hoster']['allow_dns_query'].empty?
56           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"
57         end
58       else
59         nodeinfo['misc']['resolver-recursive'] = false
60       end
61
62       return(nodeinfo)
63     rescue => e
64       raise Puppet::ParseError, "Error in nodeinfo for node #{host}, yamlfile #{yamlfile}: #{e.message}\n#{e.backtrace}"
65     end
66   end
67 end
68
69 # vim: set fdm=marker ts=2 sw=2 et: