Puppet Function: ipresolve

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

Overview

ipresolve()Any

Returns:

  • (Any)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb', line 116

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