Puppet Function: dns_ptr
- Defined in:
- lib/puppet/functions/dns_ptr.rb
- Function type:
- Ruby 4.x API
Overview
Retrieves DNS A records and returns it as an array. Each record in the array will be a IPv4 address. An optional lambda can be given to return a default value in case the lookup fails. The lambda will only be called if the lookup failed.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet/functions/dns_ptr.rb', line 5 Puppet::Functions.create_function(:dns_ptr) do dispatch :dns_ptr do param 'String', :record end dispatch :dns_ptr_with_default do param 'String', :record block_param end def dns_ptr(record) Resolv::DNS.new.getresources( record, Resolv::DNS::Resource::IN::PTR ).collect do |res| res.name.to_s end end def dns_ptr_with_default(record) ret = dns_ptr(record) if ret.empty? yield else ret end rescue Resolv::ResolvError yield end end |