Puppet Function: ipresolve

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

Overview

ipresolve()Any

Returns:

  • (Any)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'modules/wmflib/lib/puppet/parser/functions/ipresolve.rb', line 17

newfunction(:ipresolve, :type => :rvalue, :arity => -1) do |args|
  name = args[0]
  if args[1].nil?
    type = 4
  elsif args[1].to_s.downcase == 'ptr'
    type = 'ptr'
  else
    type = args[1].to_i
  end
  nameserver = args[2] # Ruby returns nil if there's nothing there
  if type == 4
    source = Resolv::DNS::Resource::IN::A
  elsif type == 6
    source = Resolv::DNS::Resource::IN::AAAA
  elsif type == 'ptr'
    source = Resolv::DNS::Resource::IN::PTR
    # Transform the provided IP address in a PTR record
    case name
    when Resolv::IPv4::Regex
      ptr = Resolv::IPv4.create(name).to_name
    when Resolv::IPv6::Regex
      ptr = Resolv::IPv6.create(name).to_name
    else
      fail("Cannot interpret #{name} as an address")
    end
    name = ptr
  else
    raise ArgumentError, 'Type must be 4, 6 or ptr'
  end
  return dns.get_resource(name, source, nameserver).to_s
end