Change the hiera 5 environment layer hiera.yaml location

asked 2017-08-03 05:04:18 -0500

geedoubleya gravatar image

Background
I am using puppet5 & hiera5 on a puppet master from separate git repos.
The code is deployed using r10k into their respective locations using the branch to environment directory mapping. Due to the environment conflict limitation in r10k (apologies if this is no longer the case) I use a separate location for my hieradata:

Puppet code - /etc/puppetlabs/code/envirnments/
Hiera code - /etc/puppetlabs/code/hieradata/

I have a global hiera.yaml file in /etc/puppetlabs/puppet/hiera.yaml and an environment specific hiera.yaml file in my hiera branch / environment location.

e.g. /etc/puppetlabs/code/hieradata/production/hiera.yaml

Problem
My environment hiera.yaml is ignored due to its location, it is expected to be where my puppet <ENVIRONMENT> code is:

/etc/puppetlabs/code/environments/production/hiera.yaml

taken from https://docs.puppet.com/puppet/5.0/hieraconfigyaml_5.html#location

but instead it is:

/etc/puppetlabs/code/hieradata/production/hiera.yaml

Solution
The only solution that I have been able to find is to locate a hiera.yaml in my puppet code repo with a datadir set to

datadir: ../../hieradata/%{::environment}/hieradata (it must be relative)

Which works ok but is not ideal so I am looking for other solutions.

Even if I set the global hiera.yaml datadir to:

/etc/puppetlabs/code/hieradata/%{::environment}/ (it can be a full path)

and do not have a hiera.yaml file in my puppet repo, hiera works, but the environmental hiera.yaml located there is ignored.

Another idea was to swap the locations but then my puppet code does not work.

So ideally what I need to do is set the environment layer hier.yaml location as it seems to be hard coded to <ENVIRONMENT>, which is where my puppet code is.

I still want to use r10k and I want to host my environmental hiera.yaml in my hiera repo, and I definitely need a separate Hiera repo!

edit retag flag offensive close merge delete

Comments

Looking at treating the hiera repo as a puppet module and importing it using the Puppetfile. Could be a suitable solution.

geedoubleya gravatar imagegeedoubleya ( 2017-08-07 03:38:30 -0500 )edit