@@ -27,6 +27,7 @@ class BuildDir
2727 # :enc [String] ENC script file (can be relative or absolute path)
2828 # :pe_enc_url [String] ENC URL (for Puppet Enterprise node classification service)
2929 # :hiera_config [String] hiera configuration file (relative to base directory)
30+ # :hiera_path [String] relative path to hiera data files (mutually exclusive with :hiera_path_strip)
3031 # :hiera_path_strip [String] string to strip off the beginning of :datadir
3132 # :puppetdb_ssl_ca [String] Path to SSL CA certificate
3233 # :puppetdb_ssl_client_key [String] String representation of SSL client key
@@ -52,9 +53,8 @@ def initialize(options = {}, logger = nil)
5253 install_puppetdb_conf ( logger , options [ :puppetdb_url ] , options [ :puppetdb_server_url_timeout ] )
5354 install_routes_yaml ( logger )
5455 end
55- unless options [ :hiera_config ] . nil?
56- install_hiera_config ( logger , options [ :hiera_config ] , options [ :hiera_path_strip ] )
57- end
56+ install_hiera_config ( logger , options ) unless options [ :hiera_config ] . nil?
57+
5858 @fact_file = install_fact_file ( logger , options ) if @facts_terminus == 'yaml'
5959 @enc = install_enc ( logger ) unless options [ :enc ] . nil? && options [ :pe_enc_url ] . nil?
6060 install_ssl ( logger , options ) if options [ :puppetdb_ssl_ca ] || options [ :puppetdb_ssl_client_cert ]
@@ -179,10 +179,10 @@ def install_enc(logger)
179179 end
180180
181181 # Install hiera config file
182- # @param hiera_config [String] Path to file, relative to checkout
183- # @param hiera_path_strip [String] Prefix to strip off when munging file
184- def install_hiera_config ( logger , hiera_config , hiera_path_strip )
182+ # @param options [Hash] Options hash
183+ def install_hiera_config ( logger , options )
185184 # Validate hiera config file
185+ hiera_config = options [ :hiera_config ]
186186 unless hiera_config . is_a? ( String )
187187 raise ArgumentError , "Called install_hiera_config with a #{ hiera_config . class } argument"
188188 end
@@ -199,10 +199,12 @@ def install_hiera_config(logger, hiera_config, hiera_path_strip)
199199 obj = YAML . load_file ( file_src )
200200 %w( yaml json ) . each do |key |
201201 next unless obj . key? ( key . to_sym )
202- next if obj [ key . to_sym ] [ :datadir ] . nil?
203- unless hiera_path_strip . nil?
204- rexp1 = Regexp . new ( '^' + hiera_path_strip )
202+ if options [ :hiera_path_strip ] . is_a? ( String )
203+ next if obj [ key . to_sym ] [ :datadir ] . nil?
204+ rexp1 = Regexp . new ( '^' + options [ : hiera_path_strip] )
205205 obj [ key . to_sym ] [ :datadir ] . sub! ( rexp1 , @tempdir )
206+ elsif options [ :hiera_path ]
207+ obj [ key . to_sym ] [ :datadir ] = File . join ( @tempdir , 'environments' , 'production' , options [ :hiera_path ] )
206208 end
207209 rexp2 = Regexp . new ( '%{(::)?environment}' )
208210 obj [ key . to_sym ] [ :datadir ] . sub! ( rexp2 , 'production' )
0 commit comments