14

just testing out hiera and I'd like to be able to view all the available data (variable=value pairs) in the hierarchy for a given node.

My Hiera hierarchy is configured as:

---
:backends:
  - yaml
  - json
:yaml:
  :datadir: C:\Puppet\hieradata
:hierarchy: 
  - "Env/%{::env}"
  - common

I can run the following to return node1's value for 'some-common' variable :

>hiera some-common ::env=node1
data

What I'd like to be able to see is all the variable=value pairs available to node1 in the hierarchy, is this possible? Thanks

Dave F
  • 180
  • 1
  • 1
  • 8

2 Answers2

8

I'm afraid this is not possible. Closest thing you could do is dump facts for specific node:

facter -y > node.yml

And then use them for look for specific keys:

hiera -y node.yml my_class:arg -d

this way you will be able to access Hiera keys based on operating system, domain, etc. (depends on your hierarchy defined in hiera.yaml).

Yet another option is to ssh into puppet master node. And use puppet lookup (should be available since Puppet 4). lookup is using by default Hiera backend (again requires hiera.yaml config file).

puppet lookup resolv_conf::nameservers --node mynode.example.net

or more verbose version:

puppet lookup resolv_conf::nameservers --merge deep --environment production --explain --node mynode.example.net
Tombart
  • 30,520
  • 16
  • 123
  • 136
1

I found another workaround - you can add top level key to your yaml data:

node-data:
  hosts:
    - localhost:3367
    - company.com
  dns: 8.8.8.8
  policy:
    retries: 3
    timeout: 5

and do puppet lookup with merge for this top level key, e.g.:

puppet lookup --merge hash/deep node_data
Schtolc
  • 1,036
  • 1
  • 12
  • 19