Puppet Function: dns_lookup
- Defined in:
- lib/puppet/functions/dns_lookup.rb
- Function type:
- Ruby 4.x API
Overview
Do a DNS lookup and returns an array of addresses. This will follow CNAMEs and return any matching IPv4 or IPv6 addresses. See the more specific functions if you only want one type returned.
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.
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 |
# File 'lib/puppet/functions/dns_lookup.rb', line 7 Puppet::Functions.create_function(:dns_lookup) do dispatch :dns_lookup do param 'String', :record end dispatch :dns_lookup_with_default do param 'String', :record block_param end def dns_lookup(record) Resolv::DNS.new.getaddresses(record).collect(&:to_s) end def dns_lookup_with_default(record) ret = dns_lookup(record) if ret.empty? yield else ret end rescue Resolv::ResolvError yield end end |