Puppet Function: extract_id

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

Overview

extract_id(Variant[Array, String] $hosts, String $hostname)Any

Custom function to extract the index from a list. The list are a list of hostname, and the index is the n’th position of the host in list

Parameters:

  • hosts (Variant[Array, String])
  • hostname (String)

Returns:

  • (Any)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/puppet/functions/extract_id.rb', line 4

Puppet::Functions.create_function(:extract_id) do
  dispatch :extract_id do
    param 'Variant[Array, String]', :hosts
    param 'String', :hostname
  end

  def extract_id(hosts, hostname)
    if hosts.class != Array
      hosts = [hosts]
    end
    hash = Hash[hosts.map.with_index.to_a]
    return hash[hostname].to_i + 1
  end
end