Puppet Function: is_ip_addresses

Defined in:
lib/puppet/functions/is_ip_addresses.rb
Function type:
Ruby 4.x API

Overview

is_ip_addresses(Variant[Array, String, Undef] $ip_addr)Any

Custom function to verify if the parameter is a string representing an ip address or an array of strings representing an ip address Returns true if all elements are proper ip addresses and false otherwise

Parameters:

  • ip_addr (Variant[Array, String, Undef])

Returns:

  • (Any)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/functions/is_ip_addresses.rb', line 6

Puppet::Functions.create_function(:is_ip_addresses) do
  dispatch :is_ip_addresses do
    param 'Variant[Array, String, Undef]', :ip_addr
  end

  def is_ip_addresses(ip_addr)
    if not ip_addr
      return false
    end
    if ip_addr.class == String
      ips = [ip_addr]
    else
      ips = ip_addr
    end
    ips.each do |ip|
      begin
        tmpip = IPAddr.new ip
      rescue
        return false
      end
    end
    return true
  end
end