aboutsummaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/extract_id.rb
blob: 61734abfacb269cd826fb345ebba519022be91b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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
module Puppet::Parser::Functions
  newfunction(:extract_id, :type => :rvalue) do |argv|
    hosts = argv[0]
    if hosts.class != Array
      hosts = [hosts]
    end
    hostname = argv[1]
    hash = Hash[hosts.map.with_index.to_a]
    return hash[hostname].to_i + 1
  end
end