Puppet Function: configvault_data

Defined in:
lib/puppet/functions/configvault_data.rb
Function type:
Ruby 4.x API

Overview

configvault_data(Hash $options, Puppet::LookupContext $context)Any

Parameters:

  • options (Hash)
  • context (Puppet::LookupContext)

Returns:

  • (Any)


1
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
# File 'lib/puppet/functions/configvault_data.rb', line 1

Puppet::Functions.create_function(:configvault_data) do
  dispatch :configvault_data do
    param 'Hash', :options
    param 'Puppet::LookupContext', :context
  end

  def configvault_data(options, context)
    context.not_found if context.cached_value('__failed__')
    begin
      raw = call_function(
        'configvault_read',
        'hiera/config.yaml',
        false,
        '',
        options['user'],
        options['bucket'],
        options['binfile']
      )
    rescue
      Puppet.info('configvault hiera failed to load')
      context.cache('__failed__', true)
      context.not_found
    end
    data = Puppet::Util::Yaml.safe_load(raw)
    if data.nil? || !data.is_a?(Hash)
      Puppet.warning('configvault hiera failed to parse')
      context.cache('__failed__', true)
      context.not_found
    end
    context.cache_all(data)
    data
  end
end