Ask Your Question
1

Where is the hiera datadir?

asked 2013-09-19 18:26:10 -0500

updated 2015-10-06 18:22:42 -0500

I am reviewing the Puppet Labs Workshop module An Introduction to Hiera (Course 03-3101) on the Learning Puppet VM version 3.x

The instructions say to create a YAML file in the Hiera data directory. But where should this data directory be?

Familiarize yourself with the hiera.yaml configuration file.

vim /etc/puppetlabs/puppet/hiera.yaml

Identify the datadir where yaml configuration files are located. Edit the common.yaml datasource,

/etc/puppetlabs/puppet/hiera.yaml says:

[root@learn ~]# cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
  - yaml
:hierarchy:
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:

So, I assume that my datadir should be set to the default /var/lib/hiera. However there is nothing there:

[root@learn ~]# ls -l /var/lib/hiera
ls: /var/lib/hiera: No such file or directory

Nor is it anywhere else that I can think of:

[root@learn ~]# ls -l /etc/puppetlabs/puppet/hieradata/
ls: /etc/puppetlabs/puppet/hieradata/: No such file or directory

And if I look for the hiera yaml files, I cannot find much:

[root@learn ~]# locate hieradata
[root@learn ~]# locate yaml |grep hiera
/etc/puppetlabs/puppet/hiera.yaml
/opt/puppet/lib/ruby/site_ruby/1.9.1/hiera/backend/yaml_backend.rb
/usr/share/doc/pe-puppet-3.2.4.pe1/examples/hiera/etc/hiera.yaml
/usr/share/doc/pe-puppet-3.2.4.pe1/examples/hiera/etc/hieradb/common.yaml
/usr/share/doc/pe-puppet-3.2.4.pe1/examples/hiera/etc/hieradb/dc1.yaml
/usr/share/doc/pe-puppet-3.2.4.pe1/examples/hiera/etc/hieradb/development.yaml

Should I expect to see a pre-existing datadir which already contains some yaml files? I am unable to get my yaml code to work, and it problem appears to be that Puppet is unable to find the Hiera data directory even though I created one manually.

[root@learn ~]# cat /etc/puppetlabs/puppet/hieradata/common.yaml
# /etc/puppetlabs/puppet/hieradata/common.yaml
---
motd: Hello there! This machine is managed by Puppet.
[root@learn ~]# puppet apply -e 'notice(hiera("motd"))'
Error: Could not find data item motd in any Hiera data file and no default supplied at line 1 on node learn.localdomain
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-09-19 19:37:09 -0500

updated 2014-07-14 19:11:19 -0500

I figured this out.

  1. Yes I needed to create the datadir. I chose /etc/puppetlabs/puppet/hieradata. This was easy. But I'm confused why it wasn't created by default.
  2. I had to specify the path to the datadir in /etc/puppetlabs/puppet/hiera.yaml.

So I thought this would all work, but Puppet was still complaining that it "Could not find data item motd in any Hiera data file".

  1. As a final step, I also had to add 'common' to the :hierarchy: section. Now /etc/puppetlabs/puppet/hiera.yaml looks like:

    :backends:
      - yaml
    :hierarchy:
      - defaults
      - "%{clientcert}"
      - "%{environment}"
      - common
      - global
    
    :yaml:
      :datadir: /etc/puppetlabs/puppet/hieradata
    

Verses the old file:

:backends:
  - yaml
:hierarchy:
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:
edit flag offensive delete link more

Comments

I just tried to get through this same lesson via puppetlabs and ran into this exact same problem. However the common entry is already there in the hiera.yaml file.

slmingol gravatar imageslmingol ( 2015-02-12 09:17:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-09-19 18:26:10 -0500

Seen: 1,132 times

Last updated: Oct 06 '15