DNS Resolution Inside Puppet

From Kyle's Wiki
Jump to: navigation, search

Sometimes you have to look up an ip address inside a puppet manifest. Here are few ways to do it.

Contents

Custom Parser Function

Put in:

modules/custom/lib/puppet/parser/functions/dnsLookup.rb:
# dnsLookup.rb
# does a DNS lookup and returns an array of strings of the results
 
require 'resolv'
 
module Puppet::Parser::Functions
    newfunction(:dnsLookup, :type => :rvalue) do |args|
        result = []
        result = Resolv.new.getaddresses(args[0])
        return result
    end
end

ERB One-Liner

$ip = inline_template("<% _erbout.concat(Resolv::DNS.open.getaddress('$Thing_To_lookup').to_s) %>")

Puppet-dnsquery Module

References

Personal tools
Namespaces

Variants
Actions
Efforts
Toolbox
Meta