module HieraPuppet
Public Instance Methods
hiera()
click to toggle source
# File lib/hiera_puppet.rb 55 def hiera 56 @hiera ||= Hiera.new(:config => hiera_config) 57 end
hiera_config()
click to toggle source
# File lib/hiera_puppet.rb 59 def hiera_config 60 config = {} 61 62 config_file = hiera_config_file 63 if config_file 64 config = Hiera::Config.load(config_file) 65 end 66 67 config[:logger] = 'puppet' 68 config 69 end
hiera_config_file()
click to toggle source
# File lib/hiera_puppet.rb 71 def hiera_config_file 72 hiera_config = Puppet.settings[:hiera_config] 73 if Puppet::FileSystem.exist?(hiera_config) 74 hiera_config 75 else 76 Puppet.warning _("Config file %{hiera_config} not found, using Hiera defaults") % { hiera_config: hiera_config } 77 nil 78 end 79 end
lookup(key, default, scope, override, resolution_type)
click to toggle source
# File lib/hiera_puppet.rb 9 def lookup(key, default, scope, override, resolution_type) 10 scope = Hiera::Scope.new(scope) 11 12 answer = hiera.lookup(key, default, scope, override, resolution_type) 13 14 if answer.nil? 15 raise Puppet::ParseError, _("Could not find data item %{key} in any Hiera data file and no default supplied") % { key: key } 16 end 17 18 answer 19 end
parse_args(args)
click to toggle source
# File lib/hiera_puppet.rb 21 def parse_args(args) 22 # Functions called from Puppet manifests like this: 23 # 24 # hiera("foo", "bar") 25 # 26 # Are invoked internally after combining the positional arguments into a 27 # single array: 28 # 29 # func = function_hiera 30 # func(["foo", "bar"]) 31 # 32 # Functions called from templates preserve the positional arguments: 33 # 34 # scope.function_hiera("foo", "bar") 35 # 36 # Deal with Puppet's special calling mechanism here. 37 if args[0].is_a?(Array) 38 args = args[0] 39 end 40 41 if args.empty? 42 raise Puppet::ParseError, _("Please supply a parameter to perform a Hiera lookup") 43 end 44 45 key = args[0] 46 default = args[1] 47 override = args[2] 48 49 return [key, default, override] 50 end