Ask Your Question
0

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

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

Red Cricket gravatar image

Hi,

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' '::fqdn=fake-fqdn.example.com' '::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 
---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - common

:yaml:
# 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.
  :datadir:

and a larger one:

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

hierarchy:
  - name: "Eyaml Data"
    lookup_key: eyaml_lookup_key
    options:
      pkcs7_private_key: /etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
      pkcs7_public_key:  /etc/puppetlabs/puppet/keys/public_key.pkcs7.pem
    paths:
     -  "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
4.10.4
# hiera --version
3.3.2
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

Red Cricket gravatar image

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

Some awesome person on slack answer my questions: https://puppetcommunity.slack.com/archives/C0W298S9G/p1498067787343619 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
fqdn: fake-fqdn.example.com
processorcount: fake-processor-count
environment: production
# /opt/puppetlabs/bin/puppet lookup --render-as s  --facts=/tmp/just-the-facts.yaml cinder::verbose
true
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

Stats

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

Seen: 43 times

Last updated: Jun 21