Puppet Function: dns_array

Defined in:
lib/puppet/parser/functions/dns_array.rb
Function type:
Ruby 3.x API

Overview

dns_array()Any

Returns a json array of hostnames and addresses from the data source. Arguments are the data source, the name of the api we are using, the token to connect to that api, and the domain to get the IPs from. When pulling for a reverse lookup zone, we submit a subnet that is understood by phpipam and it returns all entries in that subnet.

For example:

args[0] = https://ipam.dev/api/GetIPs.php?
args[1] = ipinfo
args[2] = asdlgadOuaaeiaoewr234679ds
args[3] = covermymeds.com

would return {"host1.example.com" => "192.168.30.22", ...ect}

Returns:

  • (Any)


2
3
4
5
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
# File 'lib/puppet/parser/functions/dns_array.rb', line 2

newfunction(:dns_array, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
  Returns a json array of hostnames and addresses from the data source.
  Arguments are the data source, the name of the api we are using,
  the token to connect to that api, and the domain to get the IPs from. When pulling
  for a reverse lookup zone, we submit a subnet that is understood by phpipam
  and it returns all entries in that subnet.

  For example:

      args[0] = https://ipam.dev/api/GetIPs.php?
      args[1] = ipinfo
      args[2] = asdlgadOuaaeiaoewr234679ds
      args[3] = covermymeds.com 

      would return {"host1.example.com" => "192.168.30.22", ...ect}

  ENDHEREDOC
  require "timeout"
  require "net/https"
  require "uri"
  require "json"
  begin
    timeout(40) do

    uri = URI.parse("#{args[0]}apiapp=#{args[1]}&apitoken=#{args[2]}&domain=#{args[3]}")
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.read_timeout = 30
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    response.body
    end
  end
end