]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb
Always remove acpi packages from jessie hosts
[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       nodeinfo['timeserver'] = (nodeinfo['ldap']['purpose'].respond_to?('include?') && nodeinfo['ldap']['purpose'].include?('timeserver'))
18       nodeinfo['porterbox'] = (nodeinfo['ldap']['purpose'].respond_to?('include?') && nodeinfo['ldap']['purpose'].include?('porterbox'))
19
20       if lookupvar('::mta') == 'exim4'
21         unless nodeinfo['heavy_exim']
22           nodeinfo['smarthost'] = 'mailout.debian.org'
23         end
24       end
25
26       nodeinfo['misc'] = {}
27       fqdn = lookupvar('::fqdn')
28       if fqdn and fqdn == host
29         v4ips = lookupvar('::v4ips')
30         if v4ips and v4ips.to_s != "" and v4ips.to_s != 'undefined'
31           nodeinfo['misc']['v4addrs'] = v4ips.split(',')
32
33           # find out if we are behind nat
34           intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
35           nodeinfo['misc']['natted'] = intersection.empty?
36         end
37
38         v6ips = lookupvar('::v6ips')
39         if v6ips and v6ips.to_s != "" and v6ips.to_s != 'undefined'
40           nodeinfo['misc']['v6addrs'] = v6ips.split(',')
41         end
42       end
43
44       ns = function_hiera(['nameservers'])
45       allow_dns_q = function_hiera(['allow_dns_query'])
46       if ns.empty?
47         # no nameservers known for this hoster
48         nodeinfo['misc']['resolver-recursive'] = true
49
50         if not allow_dns_q.empty?
51           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}."
52         end
53       elsif (nodeinfo['misc']['v4addrs'] and (ns & nodeinfo['misc']['v4addrs']).size > 0) or
54             (nodeinfo['misc']['v6addrs'] and (ns & nodeinfo['misc']['v6addrs']).size > 0)
55         # this host is listed as a nameserver at this location
56         nodeinfo['misc']['resolver-recursive'] = true
57
58         if allow_dns_q.empty?
59           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         end
61       else
62         nodeinfo['misc']['resolver-recursive'] = false
63       end
64
65       return(nodeinfo)
66     rescue => e
67       raise Puppet::ParseError, "Error in nodeinfo for node #{host}, yamlfile #{yamlfile}: #{e.message}\n#{e.backtrace}"
68     end
69   end
70 end
71
72 # vim: set fdm=marker ts=2 sw=2 et: