Last active
December 25, 2015 03:49
-
-
Save bodepd/6912539 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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