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