Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for rewriting hiera datadir from multiple backends #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/octocatalog-diff/catalog-util/builddir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def install_hiera_config(logger, options)

# Munge datadir in hiera config file
obj = YAML.load_file(file_src)
%w(yaml json).each do |key|
(obj[:backends] || %w(yaml json)).each do |key|
next unless obj.key?(key.to_sym)
if options[:hiera_path_strip].is_a?(String)
next if obj[key.to_sym][:datadir].nil?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
:backends:
- eyaml
- yaml
- json
:yaml:
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
:eyaml:
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
:json:
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
:hierarchy:
- servers/%{::fqdn}
- datacenter/%{::datacenter}
- platform/%{::virtual}
- os/%{::operatingsystem}/%{::lsbdistcodename}
- os/%{::operatingsystem}
- common
:merge_behavior: deeper
:logger: console
21 changes: 21 additions & 0 deletions spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,27 @@
expect(logger_str.string).to match(%r{WARNING: Hiera datadir for yaml.+/environments/production/aksdfjlkfjk})
end
end

context 'using other backends' do
it 'should rewrite all datadir' do
options = default_options.merge(
hiera_config: OctocatalogDiff::Spec.fixture_path('repos/default/config/hiera-other-backends.yaml'),
hiera_path: 'hieradata'
)
logger, logger_str = OctocatalogDiff::Spec.setup_logger
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
hiera_yaml = File.join(testobj.tempdir, 'hiera.yaml')
expect(File.file?(hiera_yaml)).to eq(true)
hiera_cfg = YAML.load_file(hiera_yaml)
expect(hiera_cfg[:backends]).to eq(%w(eyaml yaml json))
expect(hiera_cfg[:yaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
expect(hiera_cfg[:eyaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
expect(hiera_cfg[:json]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
expect(logger_str.string).not_to match(/Hiera datadir for yaml doesn't seem to exist/)
expect(logger_str.string).not_to match(/Hiera datadir for eyaml doesn't seem to exist/)
expect(logger_str.string).not_to match(/Hiera datadir for json doesn't seem to exist/)
end
end
end

describe '#install_fact_file' do
Expand Down