Add has_v[46]_ldap key to nodeinfo['misc'] to say whether we have a v[46] address...
[mirror/dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / nodeinfo.rb
index 812ff0c..e74f78b 100644 (file)
@@ -1,5 +1,7 @@
 module Puppet::Parser::Functions
   newfunction(:nodeinfo, :type => :rvalue) do |args|
+    require 'ipaddr'
+
     host = args[0]
     yamlfile = args[1]
     begin
@@ -43,6 +45,10 @@ module Puppet::Parser::Functions
         else
           nodeinfo['misc']['v6addrs'] = []
         end
+
+        # find out if we have an ipv4 and/or an ipv6 address for our host in ldap.
+        nodeinfo['misc']['has_v4_ldap'] = nodeinfo['ldap']['ipHostNumber'].any? { |x| IPAddr.new(x).ipv4? }
+        nodeinfo['misc']['has_v6_ldap'] = nodeinfo['ldap']['ipHostNumber'].any? { |x| IPAddr.new(x).ipv6? }
       end
 
       ns = call_function('hiera',['nameservers'])