Created
September 13, 2013 19:43
-
-
Save bodepd/6555165 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
| # parse config.yaml | |
| global_config_hash = get_global_config | |
| roles = get_roles_from_scenario(global_config_hash['scenario']) | |
| data_keys = get_data_keys( | |
| hiera_data_map_compile(global_config_hash, hierarchy).keys | |
| ) | |
| keys_with_defaults_hash = get_key_defaults( | |
| data_keys, | |
| hiera_compile_data(global_config_hash) | |
| ) | |
| # | |
| # compile the full data map provided the global config that drives the hierarchy | |
| # | |
| def hiera_data_map_compile(global_config_hash, hierarchy) | |
| require 'yaml' | |
| lookups = {} | |
| # array of things that map to directories given global_config_hash | |
| # ['/etc/puppet/data/scenario/2_role.yaml', '/etc/puppet/data/commmon.yaml'] | |
| compile_hiera_map(global_config_hash, hierarchy).reverse.each do |x| | |
| if File.exists?(x) | |
| key_hash = YAML.load(File.read(x)) | |
| if lookup == {} | |
| lookup = key_hash | |
| else | |
| lookup = lookup.merge(key_hash) | |
| end | |
| else | |
| # do we care if it does not exist? | |
| end | |
| end | |
| end | |
| # | |
| # take the global config and use it to compile the list of directories | |
| # | |
| def compile_hiera_map(global_config_hash, hierarchy, base_dir='/etc/puppet/data') | |
| # hierarchy = ["scenario/%{scenario}", 'common'] | |
| # global_config_hash = {'scenario' => '2_role'} | |
| hierarchy.map do |hiera_element| | |
| result = '' | |
| if hiera_element =~ /%\{([^\}]*)\}/ | |
| result = hiera_element.gsub(/%\{([^\}]*)\}/) do | |
| global_config_hash[$1] | |
| end | |
| else | |
| result = hiera_element | |
| end | |
| File.join(base_dir, "#{result}.yaml") | |
| # ['/etc/puppet/data/scenario/2_role.yaml', '/etc/puppet/data/common.yaml'] | |
| end | |
| end | |
| # does this not exist? | |
| def hiera_compile_data() | |
| end | |
| def get_key_defaults(keys, hiera_compiled_hash) | |
| result_hash = {} | |
| keys.each do |x| | |
| result_hash[x] = hiera_compiled_hash['x'] | |
| end | |
| end | |
| ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment