Module: HieraPuppet

Defined in:
lib/hiera_puppet.rb

Class Method Summary collapse

Class Method Details

.lookup(key, default, scope, override, resolution_type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hiera_puppet.rb', line 8

def lookup(key, default, scope, override, resolution_type)
  unless scope.respond_to?("[]")
    scope = Hiera::Scope.new(scope)
  end

  answer = hiera.lookup(key, default, scope, override, resolution_type)

  if answer.nil?
    raise(Puppet::ParseError, "Could not find data item #{key} in any Hiera data file and no default supplied")
  end

  answer
end

.parse_args(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hiera_puppet.rb', line 22

def parse_args(args)
  # Functions called from Puppet manifests like this:
  #
  #   hiera("foo", "bar")
  #
  # Are invoked internally after combining the positional arguments into a
  # single array:
  #
  #   func = function_hiera
  #   func(["foo", "bar"])
  #
  # Functions called from templates preserve the positional arguments:
  #
  #   scope.function_hiera("foo", "bar")
  #
  # Deal with Puppet's special calling mechanism here.
  if args[0].is_a?(Array)
    args = args[0]
  end

  if args.empty?
    raise(Puppet::ParseError, "Please supply a parameter to perform a Hiera lookup")
  end

  key      = args[0]
  default  = args[1]
  override = args[2]

  return [key, default, override]
end