]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
A big try/except around nodeinfo
authorPeter Palfrader <peter@palfrader.org>
Wed, 2 Mar 2011 20:38:02 +0000 (21:38 +0100)
committerPeter Palfrader <peter@palfrader.org>
Wed, 2 Mar 2011 20:38:02 +0000 (21:38 +0100)
modules/puppetmaster/lib/puppet/parser/functions/nodeinfo.rb

index 27888cec9caaf0b7184843d76c53bf99c09003ac..5eb6c97bb7cc1baeb985f254c63ca5179c92e39b 100644 (file)
@@ -1,57 +1,60 @@
 module Puppet::Parser::Functions
   newfunction(:nodeinfo, :type => :rvalue) do |args|
+    begin
+      host = args[0]
+      yamlfile = args[1]
 
-    host = args[0]
-    yamlfile = args[1]
+      require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb'
+      require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb'
 
-    require '/var/lib/puppet/lib/puppet/parser/functions/ldapinfo.rb'
-    require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb'
-
-    nodeinfo         = function_yamlinfo(host, yamlfile)
-    nodeinfo['ldap'] = function_ldapinfo(host, '*')
-    unless nodeinfo['ldap']['ipHostNumber']
-      raise Puppet::ParseError, "Host #{host} does not have ipHostNumber values in ldap"
-    end
-    nodeinfo['hoster'] = function_whohosts(nodeinfo['ldap']['ipHostNumber'], "/etc/puppet/modules/debian-org/misc/hoster.yaml")
-
-    nodeinfo['misc'] = {}
-    fqdn = lookupvar('fqdn')
-    if fqdn and fqdn == host
-      v4ips = lookupvar('v4ips')
-      if v4ips
-        nodeinfo['misc']['v4addrs'] = v4ips.split(',')
-
-        # find out if we are behind nat
-        intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
-        nodeinfo['misc']['natted'] = intersection.empty?
+      nodeinfo         = function_yamlinfo(host, yamlfile)
+      nodeinfo['ldap'] = function_ldapinfo(host, '*')
+      unless nodeinfo['ldap']['ipHostNumber']
+        raise Puppet::ParseError, "Host #{host} does not have ipHostNumber values in ldap"
       end
-
-      v6ips = lookupvar('v6ips')
-      if v6ips and v6ips != "no"
-        nodeinfo['misc']['v6addrs'] = v6ips.split(',')
+      nodeinfo['hoster'] = function_whohosts(nodeinfo['ldap']['ipHostNumber'], "/etc/puppet/modules/debian-org/misc/hoster.yaml")
+
+      nodeinfo['misc'] = {}
+      fqdn = lookupvar('fqdn')
+      if fqdn and fqdn == host
+        v4ips = lookupvar('v4ips')
+        if v4ips
+          nodeinfo['misc']['v4addrs'] = v4ips.split(',')
+
+          # find out if we are behind nat
+          intersection = nodeinfo['misc']['v4addrs'] & nodeinfo['ldap']['ipHostNumber']
+          nodeinfo['misc']['natted'] = intersection.empty?
+        end
+
+        v6ips = lookupvar('v6ips')
+        if v6ips and v6ips != "no"
+          nodeinfo['misc']['v6addrs'] = v6ips.split(',')
+        end
       end
-    end
 
-    if not nodeinfo['hoster']['nameservers'] or nodeinfo['hoster']['nameservers'].empty?
-      # no nameservers known for this hoster
-      nodeinfo['misc']['resolver-recursive'] = true
-
-      if nodeinfo['hoster']['allow_dns_query']
-        raise Puppet::ParseError, "No nameservers listed for #{nodeinfo['hoster']['name']} yet we should answer somebody's queries?  That makes no sense."
+      if not nodeinfo['hoster']['nameservers'] or nodeinfo['hoster']['nameservers'].empty?
+        # no nameservers known for this hoster
+        nodeinfo['misc']['resolver-recursive'] = true
+
+        if nodeinfo['hoster']['allow_dns_query']
+          raise Puppet::ParseError, "No nameservers listed for #{nodeinfo['hoster']['name']} yet we should answer somebody's queries?  That makes no sense."
+        end
+      elsif (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v4addrs']).size > 0 or
+            (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v6addrs']).size > 0
+        # this host is listed as a nameserver at this location
+        nodeinfo['misc']['resolver-recursive'] = true
+
+        if not nodeinfo['hoster']['allow_dns_query'] or nodeinfo['hoster']['allow_dns_query'].empty?
+          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"
+        end
+      else
+        nodeinfo['misc']['resolver-recursive'] = false
       end
-    elsif (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v4addrs']).size > 0 or
-          (nodeinfo['hoster']['nameservers'] & nodeinfo['misc']['v6addrs']).size > 0
-      # this host is listed as a nameserver at this location
-      nodeinfo['misc']['resolver-recursive'] = true
 
-      if not nodeinfo['hoster']['allow_dns_query'] or nodeinfo['hoster']['allow_dns_query'].empty?
-        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"
-      end
-    else
-      nodeinfo['misc']['resolver-recursive'] = false
+      return(nodeinfo)
+    rescue => e
+      raise Puppet::ParseError, "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}"
     end
-
-    return(nodeinfo)
   end
 end