Ask Your Question

command line hiera not work after switch to hiera5 hiera.yaml

asked 2017-06-21 12:18:44 -0600

Red Cricket gravatar image


I am switching to hiera5. My opensource puppet master and nodes are working fine and are able to consume the hiera data, but I would like to be able to run hiera from the command line on my puppet master to QA my hiera data. With the previous version of hiera I had a shell script that execute a bunch of hiera commands. For example it would execute:

/opt/puppetlabs/bin/hiera controller_vip_name '::pod_prefix=fab-aos' '::pod_role=controller' '::ipaddress_eth0=123.456.789.012' '' '::processorcount=fake-processor-count' environment=production

The problem is that the above command and all of the commands executed by my script return nil.

If I run the above command on my puppet master with debug I get this output:

DEBUG: 2017-06-21 16:54:29 +0000: Hiera YAML backend starting
DEBUG: 2017-06-21 16:54:29 +0000: Looking up controller_vip_name in YAML backend
DEBUG: 2017-06-21 16:54:29 +0000: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: 2017-06-21 16:54:29 +0000: Looking for data source common
DEBUG: 2017-06-21 16:54:29 +0000: Cannot find datafile /etc/puppetlabs/code/environments/production/hieradata/common.yaml, skipping

I have these hiera.yaml files on my puppet master:

# cat /etc/puppetlabs/puppet/hiera.yaml 
  - yaml
  - "nodes/%{::trusted.certname}"
  - common

# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.

and a larger one:

# cat /etc/puppetlabs/code/environments/production/hiera.yaml 
version: 5
  data_hash: yaml_data  # Use the built-in YAML backend.
  datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"

  - name: "Eyaml Data"
    lookup_key: eyaml_lookup_key
      pkcs7_private_key: /etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
      pkcs7_public_key:  /etc/puppetlabs/puppet/keys/public_key.pkcs7.pem
     -  "nodes/%{::trusted.certname}.yaml"
     -  "nodes/%{::pod_role}.yaml"
     ... many more paths omitted for brevity ....

I believe I have to most up-to-date software installed:

# puppet -V
# hiera --version
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-06-21 13:31:15 -0600

Red Cricket gravatar image

updated 2017-06-21 16:20:45 -0600

Some awesome person on slack answer my questions: In summary I need to use puppet lookup instead of calling hiera directly.

Update: One thing I found that isn't so great is that the node used in the puppet lookup command must be already paired to the puppet master. My use case is one where I'd QA the hiera data before setting up a node.

Ok the guys on slack got me squared away ... I need to create a facts file (either json or yaml) and I do not need to specify a node. So I would have this ...

# cat /tmp/just-the-facts.yaml 
os_prefix: my-aos
os_role: controller
ipaddress_eth0: 123.456.789.012
processorcount: fake-processor-count
environment: production
# /opt/puppetlabs/bin/puppet lookup --render-as s  --facts=/tmp/just-the-facts.yaml cinder::verbose
edit flag offensive delete link more

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


Asked: 2017-06-21 12:18:44 -0600

Seen: 334 times

Last updated: Jun 21 '17