Skip to content

Commit 4aceadc

Browse files
authored
Merge pull request #32 from masterzen/feature/support-other-hiera-backends
Support for rewriting hiera datadir from multiple backends
2 parents f17f56a + 870201f commit 4aceadc

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def install_hiera_config(logger, options)
197197

198198
# Munge datadir in hiera config file
199199
obj = YAML.load_file(file_src)
200-
%w(yaml json).each do |key|
200+
(obj[:backends] || %w(yaml json)).each do |key|
201201
next unless obj.key?(key.to_sym)
202202
if options[:hiera_path_strip].is_a?(String)
203203
next if obj[key.to_sym][:datadir].nil?
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
:backends:
3+
- eyaml
4+
- yaml
5+
- json
6+
:yaml:
7+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
8+
:eyaml:
9+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
10+
:json:
11+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
12+
:hierarchy:
13+
- servers/%{::fqdn}
14+
- datacenter/%{::datacenter}
15+
- platform/%{::virtual}
16+
- os/%{::operatingsystem}/%{::lsbdistcodename}
17+
- os/%{::operatingsystem}
18+
- common
19+
:merge_behavior: deeper
20+
:logger: console

spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,27 @@
231231
expect(logger_str.string).to match(%r{WARNING: Hiera datadir for yaml.+/environments/production/aksdfjlkfjk})
232232
end
233233
end
234+
235+
context 'using other backends' do
236+
it 'should rewrite all datadir' do
237+
options = default_options.merge(
238+
hiera_config: OctocatalogDiff::Spec.fixture_path('repos/default/config/hiera-other-backends.yaml'),
239+
hiera_path: 'hieradata'
240+
)
241+
logger, logger_str = OctocatalogDiff::Spec.setup_logger
242+
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
243+
hiera_yaml = File.join(testobj.tempdir, 'hiera.yaml')
244+
expect(File.file?(hiera_yaml)).to eq(true)
245+
hiera_cfg = YAML.load_file(hiera_yaml)
246+
expect(hiera_cfg[:backends]).to eq(%w(eyaml yaml json))
247+
expect(hiera_cfg[:yaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
248+
expect(hiera_cfg[:eyaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
249+
expect(hiera_cfg[:json]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
250+
expect(logger_str.string).not_to match(/Hiera datadir for yaml doesn't seem to exist/)
251+
expect(logger_str.string).not_to match(/Hiera datadir for eyaml doesn't seem to exist/)
252+
expect(logger_str.string).not_to match(/Hiera datadir for json doesn't seem to exist/)
253+
end
254+
end
234255
end
235256

236257
describe '#install_fact_file' do

0 commit comments

Comments
 (0)