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

hiera_config doesn't override puppet 5 layer 3 hiera.yaml #626

Open
LongLiveCHIEF opened this issue Dec 7, 2017 · 3 comments
Open

hiera_config doesn't override puppet 5 layer 3 hiera.yaml #626

LongLiveCHIEF opened this issue Dec 7, 2017 · 3 comments

Comments

@LongLiveCHIEF
Copy link

As of puppet 5, hiera is now native to puppet. When a module as hiera.yaml at it's root, it's given precedence over any values passed in your spec/spec_helper.rb for hiera_config.

As an example, my module's hiera.yaml hierarchy contains a eyaml data source. This has caused some issues (documented here) which I tried to get around by providing rspec-puppet a different hiera.yaml file to use for testing, that didn't contain the eyaml data sources.

Unfortunately, it appears that even though this value is passed, it doesn't trump the layer 3 hiera specification of the module's own hiera.yaml file. Even though i've confirmed that rspec-puppet loads the config file specified in my spec/spec_helper.rb, it does not use values from the data sources in that configs hierarchy. It uses the data-sources defined in the module's own hiera.yaml file.

Is there a way we can ensure that the following overrides the layer 3 hiera.yaml file in puppet 5 modules?

require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixutes'))

RSpec.configure do |c|
  c.default_facts = default_facts
  c.hiera_config = File.join(fixture_path, 'hiera.yaml')
end
@fabx
Copy link

fabx commented Dec 13, 2017

+1

@rodjek
Copy link
Owner

rodjek commented Jan 15, 2018

@LongLiveCHIEF Can you create a simple repo with failing tests that show your expected behavior here? I had a look at the repo you provided in the linked issue but there were no failing tests in there. I'm not entirely sure what you're trying to do here (hiera 5 is a very different beast to hiera 3) and some failing examples will clarify things for me :)

@nabertrand
Copy link
Contributor

I added the following to spec/spec_helper.rb to cause Puppet to use a hiera.yaml from the module spec folder if found. The code could definitely be extended to support custom hiera.yaml locations for each module, but this got me around the eyaml issue. I decided to search the spec folder instead of hard-coding a path as there doesn't seem to be a standard location for spec hiera.yaml files. For example, some sites suggest spec/fixtures/hiera/hiera.yaml, whereas others suggest spec/fixtures/hiera.yaml.

module Puppet
  class Pops::Lookup::ModuleDataProvider
    def configuration_path(lookup_invocation)
      pr = provider_root(lookup_invocation)
      pr.join('spec').find do |path|
        if path.basename.to_s.eql?(Puppet::Pops::Lookup::HieraConfig::CONFIG_FILE_NAME)
          return path
        end
      end
      pr + Puppet::Pops::Lookup::HieraConfig::CONFIG_FILE_NAME
    end
  end
end

If you'd rather use one hiera.yaml file for everything, the following seemed to work to tell Puppet to use spec/fixtures/hiera.yaml for everything:

module Puppet
  class Pops::Lookup::ModuleDataProvider
    def configuration_path(lookup_invocation)
      Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'hiera.yaml')))
    end
  end
end

@rodjek I'm not sure if @LongLiveCHIEF is experiencing the exact same issue as me, but when I run into trouble is when a module listed in .fixtures.yml has a module hiera.yaml that is configured to use eyaml. This monkey patch to Puppet allows me to override which hiera.yaml Puppet uses for the fixture module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants