Question

I have been experimenting with hiera for configuration data. The hiera.yaml file has the following configuration:

---
:backends:
  - yaml
:hierarchy:
  - "servers/%{hostname}"
  - common

but when I run hiera from the command line to test it,

hiera some::var hostname=foo

it does not pick up the configuration from servers/foo/yaml. Adding the -d (debug) option shows that it doesn't even look at that file. Instead, it says something like:

Looking for data source services/foo
Cannot find database /etc/puppet/hiera/services/foo.yaml, skipping

So, two questions:

  1. Why is it not looking in the servers directory?

  2. Why is it looking in a "services" directory? (Note that it looks for things in the services directory even if we remove the "servers/%{::hostname}" line from the hiera.yaml file!)

    If by default hiera looks for things in special directories like "services", then where is this documented?

Was it helpful?

Solution 2

Apparently, the configuration will work if: hiera is run with the -c option to specify the exact location of the configuration file. (A symlink from /etc/hiera.yaml did not work, though that was a suggestion from another forum https://ask.puppetlabs.com/question/3149/where-does-hiera-search-for-data-sources/?answer=3152#post-id-3152)

OTHER TIPS

I think the reason may be that a) you are not using the default location for hiera datadir (which is /var/lib/hiera) and b) you have forgotten to specify that datadir within the hiera.yaml (or whatever filename you want your hiera config file to be). That is what a possible solution might be is just adding the following to your hiera config file:

:yaml:
    :datadir: /tmp/var-lib-hiera

Check out the following example:

/tmp/var-lib-hiera $ hiera -c hiera.yaml some::var hostname=foo
100

/tmp/var-lib-hiera $ tree
.
├── hiera.yaml
└── servers
    └── foo.yaml

/tmp/var-lib-hiera $ head  hiera.yaml servers/foo.yaml 

==> hiera.yaml <==
---
:backends:
    - yaml
:hierarchy:
    - "servers/%{hostname}"
    - common
:yaml:
    :datadir: /tmp/var-lib-hiera


==> servers/foo.yaml <==
some::var: 100

If you are using puppet you can set the location of the hiera file in e master section of puppet.conf so you don't have to provide it on cmd line.

See: http://docs.puppetlabs.com/references/latest/configuration.html#hieraconfig

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top