diff --git a/manifests/eyaml.pp b/manifests/eyaml.pp index c918fe8..1a103ef 100644 --- a/manifests/eyaml.pp +++ b/manifests/eyaml.pp @@ -51,7 +51,6 @@ $keysdir = dirname($_keysdir) if ( $create_keys == true ) { - exec { 'createkeys': user => $owner, cwd => $keysdir, diff --git a/manifests/init.pp b/manifests/init.pp index 4198ba1..1ca1c7c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -111,7 +111,6 @@ #Deprecated $gem_source = undef, ) inherits ::hiera::params { - if $keysdir { $_keysdir = $keysdir } else { @@ -164,7 +163,6 @@ } if ( $eyaml_gpg ) or ( $eyaml ) { - $eyaml_real_datadir = empty($eyaml_datadir) ? { false => $eyaml_datadir, true => $datadir, @@ -176,7 +174,6 @@ } else { $requested_backends = unique(concat(['eyaml'], $backends)) } - } else { $requested_backends = $backends $eyaml_real_datadir = undef @@ -207,14 +204,14 @@ # the above logic. This was neccessary in order to maintain compability # with prior versions of this module $eyaml_options = { - 'eyaml' => delete_undef_values({ - 'datadir' => $eyaml_real_datadir, - 'extension' => $eyaml_extension, - 'pkcs7_private_key' => $_eyaml_pkcs7_private_key, - 'pkcs7_public_key' => $_eyaml_pkcs7_public_key, - 'encrypt_method' => $encrypt_method, - 'gpg_gnupghome' => $gpg_gnupghome, - 'gpg_recipients' => $eyaml_gpg_recipients, + 'eyaml' => delete_undef_values( { + 'datadir' => $eyaml_real_datadir, + 'extension' => $eyaml_extension, + 'pkcs7_private_key' => $_eyaml_pkcs7_private_key, + 'pkcs7_public_key' => $_eyaml_pkcs7_public_key, + 'encrypt_method' => $encrypt_method, + 'gpg_gnupghome' => $gpg_gnupghome, + 'gpg_recipients' => $eyaml_gpg_recipients, }), } $yaml_options = { 'yaml' => { 'datadir' => $datadir } } @@ -228,7 +225,7 @@ # catch that error here and notify the user $missing_backends = difference($backends, keys($backend_data)) if count($missing_backends) > 0 { - fail("The supplied backends: ${missing_backends} are missing from the backend_options hash:\n ${backend_options}\n + fail("The supplied backends: ${missing_backends} are missing from the backend_options hash:\n ${backend_options}\n or you might be using symbols in your hiera data") } @@ -250,18 +247,19 @@ # Determine hiera version case $hiera_version { - '5': { if ($hierarchy !~ Hiera::Hiera5_hierarchy) { - fail('`hierarchy` should be an array of hash') - } - else - { $hiera_template = epp('hiera/hiera.yaml.epp', - { - 'hiera_version' => $hiera_version, - 'hiera5_defaults' => $hiera5_defaults, - 'hierarchy' => $hierarchy - }) - } - } # Apply epp if hiera version is 5 + '5': { + if ($hierarchy !~ Hiera::Hiera5_hierarchy) { + fail('`hierarchy` should be an array of hash') + } + else { + $hiera_template = epp('hiera/hiera.yaml.epp', + { + 'hiera_version' => $hiera_version, + 'hiera5_defaults' => $hiera5_defaults, + 'hierarchy' => $hierarchy + }) + } + } # Apply epp if hiera version is 5 default: { $hiera_template = template('hiera/hiera.yaml.erb') } # Apply erb for default version 3 } file { $hiera_yaml: diff --git a/manifests/install.pp b/manifests/install.pp index 56bd320..ce8cb28 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -6,7 +6,6 @@ $gem_source = undef, $gem_install_options = $hiera::gem_install_options, ) { - # $gem_install_options is typically used for specifying a proxy Package { install_options => $gem_install_options, diff --git a/manifests/params.pp b/manifests/params.pp index 623ec8f..c1dd731 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -16,7 +16,7 @@ class hiera::params { $confdir = $::settings::confdir $hiera_version = '3' - $hiera5_defaults = {'datadir' => 'data', 'data_hash' => 'yaml_data'} + $hiera5_defaults = { 'datadir' => 'data', 'data_hash' => 'yaml_data' } $package_ensure = 'present' $package_name = 'hiera' $hierarchy = [] diff --git a/spec/classes/hiera_spec.rb b/spec/classes/hiera_spec.rb index daff4da..2820a4f 100644 --- a/spec/classes/hiera_spec.rb +++ b/spec/classes/hiera_spec.rb @@ -59,13 +59,16 @@ merge_behavior: 'deeper', eyaml: true, datadir: '/etc/puppetlabs/code/environments/%{::environment}/hieradata', - backends: %w[yaml eyaml json yamll], + backends: %w[yaml eyaml json yamll redis], 'backend_options' => { 'json' => { 'datadir' => '/etc/puppet/json_data/data' }, 'yamll' => { 'datadir' => '/etc/puppet/yamll_data/data' + }, + 'redis' => { + 'deserialize' => '!ruby/sym json' } } } @@ -78,9 +81,13 @@ expect(content).not_to include('!ruby/sym') end + it 'testing gsub and regex' do + expect('!ruby/sym json'.to_yaml.gsub(/---\s+/, '').gsub(/(?:'|")(\!ruby\/sym\s)(.*)(?:'|")/, ':\2')).to eq ":json\n" + end + it 'include backends' do backends = YAML.load(content)[:backends] - expect(backends).to eq(%w[yaml eyaml json yamll]) + expect(backends).to eq(%w[yaml eyaml json yamll redis]) end it 'include json backend' do backend = YAML.load(content)[:json] @@ -90,6 +97,10 @@ backend = YAML.load(content)[:yamll] expect(backend[:datadir]).to eq('/etc/puppet/yamll_data/data') end + it 'include redis backend with deserialize' do + redis_backend = YAML.load(content)[:redis] + expect(redis_backend[:deserialize]).to eq(:json) + end # rubocop:disable RSpec/MultipleExpectations it 'include eyaml backend' do eyaml_backend = YAML.load(content)[:eyaml] diff --git a/templates/hiera.yaml.erb b/templates/hiera.yaml.erb index b2a1f6c..7f95ab9 100644 --- a/templates/hiera.yaml.erb +++ b/templates/hiera.yaml.erb @@ -12,7 +12,8 @@ <%- all_backends = @backend_data.inject({}){|data,(k,v)| data[k.to_sym] = v; data} -%> <%# symobolize backend option keys because hiera backends assume the usage of symbols :( -%> <%- b_data = all_backends[backend_name.to_sym].inject({}){|data,(k,v)| data[k.to_sym] = v; data} -%> -<%= { backend_name.to_sym => b_data }.to_yaml.gsub(/---\s+/, '').gsub(/\!ruby\/sym\s/, ':') -%> +<%# Replacing '!ruby/sym' with ':' and appending the string (value) between quotes to form the symbol -%> +<%= { backend_name.to_sym => b_data }.to_yaml.gsub(/---\s+/, '').gsub(/(?:'|")(\!ruby\/sym\s)(.*)(?:'|")/, ':\2') -%> <%- end -%> <% if @merge_behavior -%>