Skip to content

Instantly share code, notes, and snippets.

@bodepd
Last active December 25, 2015 03:49
Show Gist options
  • Select an option

  • Save bodepd/6912539 to your computer and use it in GitHub Desktop.

Select an option

Save bodepd/6912539 to your computer and use it in GitHub Desktop.
def get_keys_per_dir(dir, scope={}, is_data_mapping=false, interpolate_hiera_data=true)
begin
require 'hiera'
rescue
Puppet.Warning("Hiera libraries could not be loaded")
return {}
end
# get the hiera config file
hiera_config_file = File.join(Puppet[:confdir], 'hiera.yaml')
data = {}
# iterate through all data sources from this config file
Hiera::Backend.datasources(
scope,
nil,
get_hierarchy(hiera_config_file)
) do |source|
# search for data overrides in the global_hiera_params directory
yamlfile = get_data_file(File.join(data_dir, dir), "#{source}.yaml")
Puppet.debug("Searching #{yamlfile} for keys")
if File.exists?(yamlfile)
config = YAML.load_file(yamlfile)
config.each do |k, v|
data = yield(k,v,data)
end
end
end
data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment