Puppet Function: dnsquery::cname

Defined in:
vendor_modules/dnsquery/lib/puppet/functions/dnsquery/cname.rb
Function type:
Ruby 4.x API

Overview

dnsquery::cname(Stdlib::Fqdn $domain, Optional[Optional[Dnsquery::Config_info]] $config_info, Optional[Callable] &$block)String

Retrieves a DNS CNAME record for a domain and returns it as a string.

Parameters:

  • domain (Stdlib::Fqdn)

    the dns domain to lookup

  • config_info (Optional[Optional[Dnsquery::Config_info]])

    used to override the config for Resolve::DNS.new

  • &block (Optional[Callable])

    an optional lambda to return a default value in case the lookup fails

Returns:

  • (String)

    An string representing the CNAME of a domain



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'vendor_modules/dnsquery/lib/puppet/functions/dnsquery/cname.rb', line 6

Puppet::Functions.create_function(:'dnsquery::cname') do
  # @param domain the dns domain to lookup
  # @param config_info used to override the config for Resolve::DNS.new
  # @param block an optional lambda to return a default value in case the lookup fails
  # @return An string representing the CNAME of a domain
  dispatch :dns_cname do
    param 'Stdlib::Fqdn', :domain
    optional_param 'Optional[Dnsquery::Config_info]', :config_info
    optional_block_param :block
    return_type 'String'
  end

  def dns_cname(domain, config_info = nil)
    resolver = PuppetX::Voxpupuli::Dnsquery::Utils.resolver(config_info)
    resolver.getresource(
      domain, Resolv::DNS::Resource::IN::CNAME
    ).name.to_s
  rescue Resolv::ResolvError
    block_given? ? yield : raise
  end
end