X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fwhohosts.rb;h=022ca895af991943211fefb06c4dc166f31b8ee1;hb=a07d3c87c702f358bd36d52f423c1f437307b015;hp=2835cef2d3f8d8ea0b62a4bd679c279db90a32e5;hpb=af54a28ce3583c22c02a9e59277bb173fb1704f1;p=dsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb index 2835cef2..022ca895 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -9,17 +9,26 @@ module Puppet::Parser::Functions $KCODE = 'utf-8' - ans = "unknown" + ans = {"name": "unknown"} yaml = YAML.load_file(yamlfile) if (nodeinfo['ldap'].has_key?('ipHostNumber')) nodeinfo['ldap']['ipHostNumber'].each do |addr| yaml.keys.each do |hoster| - if yaml[hoster].has_key?'netrange' - yaml[hoster]['netrange'].each do |net| + if yaml[hoster].kind_of?(Hash) and yaml[hoster].has_key?('netrange') + netrange = yaml[hoster]['netrange'] + else + next + end + + netrange.each do |net| + begin if IPAddr.new(net).include?(addr) - return hoster + ans = yaml[hoster] + ans['name'] = hoster end + rescue Exception => e + raise "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" end end end