Puppet Function: ipaddresses

Defined in:
lib/puppet/parser/functions/ipaddresses.rb
Function type:
Ruby 3.x API

Overview

ipaddresses()Array[Strin

Return an Array of all IP addresses known to be associated with the client.

If an argument is passed, and is not false, then only return non-local addresses.

Returns:

  • (Array[Strin)

    Array[Strin



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/parser/functions/ipaddresses.rb', line 2

newfunction(:ipaddresses, :type => :rvalue, :doc => <<-EOM) do |args|

  only_remote = args[0]
    Return an `Array` of all IP addresses known to be associated with the
    client.

    If an argument is passed, and is not `false`, then only return
    non-local addresses.

    @return [Array[String]]
  EOM

  retval = []
  lookupvar('::interfaces').split(',').each do |iface|
    iface_addr = lookupvar("::ipaddress_#{iface}")

    retval << iface_addr unless (iface_addr.nil? or iface_addr.strip.empty?)
  end

  retval.delete_if{|x| x =~ /^127/} if only_remote

  retval
end