]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb
make this explode
[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       raise Puppet::ParseError, "#{nodeinfo['ldap']['purpose']}"
17       nodeinfo['buildd'] = nodeinfo['ldap']['purpose'].include?('buildd')
18
19       nodeinfo['misc'] = {}
20       fqdn = lookupvar('::fqdn')
21       if fqdn and fqdn == host
22         v4ips = lookupvar('::v4ips')
23         if v4ips
24           nodeinfo['misc']['v4addrs'] = v4ips.split(',')
25
26           # find out if we are behind nat
27           intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
28           nodeinfo['misc']['natted'] = intersection.empty?
29         end
30
31         v6ips = lookupvar('::v6ips')
32         if v6ips and v6ips != ""
33           nodeinfo['misc']['v6addrs'] = v6ips.split(',')
34         end
35       end
36
37       if not nodeinfo['hoster']['nameservers'] or nodeinfo['hoster']['nameservers'].empty?
38         # no nameservers known for this hoster
39         nodeinfo['misc']['resolver-recursive'] = true
40
41         if nodeinfo['hoster']['allow_dns_query']
42           raise Puppet::ParseError, "No nameservers listed for #{nodeinfo['hoster']['name']} yet we should answer somebody's queries?  That makes no sense."
43         end
44       elsif (nodeinfo['misc']['v4addrs'] and (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v4addrs']).size > 0) or
45             (nodeinfo['misc']['v6addrs'] and (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v6addrs']).size > 0)
46         # this host is listed as a nameserver at this location
47         nodeinfo['misc']['resolver-recursive'] = true
48
49         if not nodeinfo['hoster']['allow_dns_query'] or nodeinfo['hoster']['allow_dns_query'].empty?
50           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"
51         end
52       else
53         nodeinfo['misc']['resolver-recursive'] = false
54       end
55
56       return(nodeinfo)
57     rescue => e
58       raise Puppet::ParseError, "Error in nodeinfo for node #{host}, yamlfile #{yamlfile}: #{e.message}\n#{e.backtrace}"
59     end
60   end
61 end
62
63 # vim: set fdm=marker ts=2 sw=2 et: