Puppet Function: dns_txt
- Defined in:
- lib/puppet/functions/dns_txt.rb
- Function type:
- Ruby 4.x API
Overview
Retrieves DNS TXT records and returns it as an array. Each record in the array will be a array containing the strings of the TXT record.
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_txt.rb', line 6 Puppet::Functions.create_function(:dns_txt) do dispatch :dns_txt do param 'String', :record end dispatch :dns_txt_with_default do param 'String', :record block_param end def dns_txt(record) Resolv::DNS.new.getresources( record, Resolv::DNS::Resource::IN::TXT ).collect do |res| res.strings end end def dns_txt_with_default(record) ret = dns_txt(record) if ret.empty? yield else ret end rescue Resolv::ResolvError yield end end |