Puppet Function: hiera_lookup

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

Overview

hiera_lookup()Any

Returns:

  • (Any)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet/parser/functions/hiera_lookup.rb', line 4

newfunction(:hiera_lookup, :type => :rvalue) do |args|
  certname = args[0]
  key = args[1]

  uri = URI.parse('http://localhost:8080/v2/nodes/' + certname + '/facts')
  result = Net::HTTP.get(uri)
  puppetdb_facts = JSON.parse(result)

  facts = {}
  puppetdb_facts.each do |fact|
    name = '::' + fact['name']
    value = fact['value']
    facts[name] = value
  end

  hiera = Hiera.new(:config => HieraPuppet.hiera_config)
  hiera.lookup(key, 'default', facts)
end