Puppet Function: dns_mx
- Defined in:
- lib/puppet/functions/dns_mx.rb
- Function type:
- Ruby 4.x API
Overview
Retrieves DNS MX records and returns it as an array. Each record in the array will be an array of hashes with a preference and exchange field.
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 35 36 37 |
# File 'lib/puppet/functions/dns_mx.rb', line 6 Puppet::Functions.create_function(:dns_mx) do dispatch :dns_mx do param 'String', :record end dispatch :dns_mx_with_default do param 'String', :record block_param end def dns_mx(record) Resolv::DNS.new.getresources( record, Resolv::DNS::Resource::IN::MX ).collect do |res| { 'preference' => res.preference, 'exchange' => res.exchange.to_s } end end def dns_mx_with_default(record) ret = dns_mx(record) if ret.empty? yield else ret end rescue Resolv::ResolvError yield end end |