Puppet Function: dns_a
- Defined in:
- lib/puppet/functions/dns_a.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.
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 34 |
# File 'lib/puppet/functions/dns_a.rb', line 6 Puppet::Functions.create_function(:dns_a) do dispatch :dns_a do param 'String', :record end dispatch :dns_a_with_default do param 'String', :record block_param end def dns_a(record) Resolv::DNS.new.getresources( record, Resolv::DNS::Resource::IN::A ).collect do |res| res.address.to_s end end def dns_a_with_default(record) ret = dns_a(record) if ret.empty? yield else ret end rescue Resolv::ResolvError yield end end |