I'm trying to load a hiera file according to a specific flag.

Hiera hierarachy configuration is

  - "%{environment}/%{::fqdn}"
  - "%{environment}/%{nodetype}"
  - "%{environment}/%{calling_module}"
  - "%{environment}"
  - "common/%{calling_module}"
  - "common"

In fact in want to factorize some configuration at the "nodetype" level. Goal is to avoid putting the same hiera "block" inside files:

  • environment/test/myhost1.example.com.yaml
  • environment/test/myhost2.example.com.yaml
  • environment/test/myhost3.example.com.yaml

but instead but common part in :

  • environment/test/nfs-server.yaml for all nfs servers related common configuration
  • environment/test/backend-server.yaml for all backend servers related common

After that all servers would get their own specific values with the fqdn yaml file. (this part is ok)

Currently, i don't know how to provide the "nodetype" data to hiera context.

I tried to put it into the main manifest file like (yeah I read the doc and I know it a bad idea but even with despair attempt, it don't work anyway)

node 'nfs1.example.com', 'nfs2.example.com' {
  $nodetype= 'nfs-server'

but the file environment/test/nfs-server.yaml is not loaded by hiera.

I also tried to use custom fact but using a custom fact with


File is send to the host of the agent but again here, hiera don't use the dedicated file.

Notice: /File[/var/lib/puppet/facts.d/host-fact-test.txt]/ensure: defined content as '{md5}d7492faae1bfe55f65f9958a7a5f6df9'

If I use a notify puppet command, the value is ok

if $nodetype== 'nfs-server' {
  notify {"Running with \$nodetype ${nodetype} ID defined":
    withpath => true,


Notice: /Stage[main]/attemps/Notify[Running with $nodetype nfs-server ID defined]/message: Running with $nodetype nfs-server ID defined

Stack is Puppet opensource on Ubuntu 14 so versions are:

  • puppet 3.8.4
  • hiera 1.3.4
  • facter 2.4.4

Any idea or suggestion to make it work (or achieve a similar behavior) ?

  • have tried using %{::nodetype} ? – c4f4t0r Dec 26 '15 at 19:12
  • Yes putting %{::nodetype} or %{nodetype} don't change a thing in /etc/hiera.yaml file – DevOps Jan 4 '16 at 13:52

The Puppet master process usually does not use the configuration in /etc/hiera.yaml, which can be confusing. With Puppet 3.x, it's usually /etc/puppet/hiera.yaml.

You can make sure using (as root)

puppet master --configprint hiera_config

on the master machine.

| improve this answer | |
  • puppet master --configprint hiera_config is /etc/puppet/hiera.yaml so the right hiera file is used. – DevOps Jan 6 '16 at 15:03
  • 1
    @TheCodeKiller OK, I was mislead by your earlier comment alluding to /etc/hiera.yaml then. To debug this, you will want to run hiera -d -c /etc/puppet/hiera.yaml <key> ::fqdn=nfs1.example.com nodetype=nfs-server. It shows you information about the data source lookups. – Felix Frank Jan 7 '16 at 11:52
  • It shows the attended value as it use the right value from the nfs-server.yaml file as attended using nearly (just add the environment) the provided command line. We retest it with a notify, and it seems to work now ! We will perform additional tests to ensure all is fine now. – DevOps Jan 8 '16 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.