Skip to content

Commit 18e5307

Browse files
committed
Support hiera.yaml backend declared as a string instead of array
1 parent c42b8af commit 18e5307

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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

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

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,24 @@
514514
expect(logger_str.string).not_to match(/Hiera datadir for json doesn't seem to exist/)
515515
end
516516
end
517+
518+
# https://github.com/github/octocatalog-diff/issues/107
519+
# https://docs.puppet.com/hiera/3.3/configuring.html#backends
520+
context 'with backend as a string' do
521+
it 'should handle backend declared as a single string' do
522+
options = default_options.merge(
523+
hiera_config: OctocatalogDiff::Spec.fixture_path('repos/default/config/hiera-backend-as-string.yaml'),
524+
hiera_path: 'hieradata'
525+
)
526+
logger, _logger_str = OctocatalogDiff::Spec.setup_logger
527+
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
528+
hiera_yaml = File.join(testobj.tempdir, 'hiera.yaml')
529+
expect(File.file?(hiera_yaml)).to eq(true)
530+
hiera_cfg = YAML.load_file(hiera_yaml)
531+
expect(hiera_cfg[:backends]).to eq('yaml')
532+
expect(hiera_cfg[:yaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
533+
end
534+
end
517535
end
518536

519537
describe '#install_fact_file' do

0 commit comments

Comments
 (0)