Module: Yutani::Hiera

Defined in:
lib/yutani/hiera.rb

Class Method Summary collapse

Class Method Details

.hiera(config_override = {}) ⇒ Object



4
5
6
# File 'lib/yutani/hiera.rb', line 4

def hiera(config_override={})
  @hiera ||= init_hiera(config_override)
end

.init_hiera(override = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/yutani/hiera.rb', line 8

def init_hiera(override={})
  conf = Yutani.config(override)

  # hiera_config_file trumps hiera_config
  ::Hiera.new(config:
    conf.fetch('hiera_config_file', conf['hiera_config'])
  )
end

.lookup(k, scope) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yutani/hiera.rb', line 17

def lookup(k, scope)
  # hiera expects strings, not symbols
  hiera_scope = scope.inject({}){|h,(k,v)| h[k.to_s] = v.to_s; h}
  Yutani.logger.debug "hiera scope: %s" % hiera_scope

  v = Yutani::Hiera.hiera.lookup(k.to_s, nil, hiera_scope)
  Yutani.logger.warn "hiera couldn't find value for key #{k}" if v.nil?

  # let us use symbols for hash keys
  Yutani::Utils.convert_nested_hash_to_indifferent_access(v)
end