Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiera command line: How do I view all data in the hierarchy for a given node?

Tags:

puppet

hiera

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

like image 519
Dave F Avatar asked Jan 07 '15 09:01

Dave F


People also ask

How does Hiera handle node-specific variables?

With node-specific variables, each node gets a customized set of paths to data. The hierarchy is always the same. After Hiera replaces the variables to make a list of concrete data sources, it checks those data sources in the order they were written.

Is the Hiera hierarchy always the same?

The hierarchy is always the same. After Hiera replaces the variables to make a list of concrete data sources, it checks those data sources in the order they were written.

How does H Hiera look up data?

Hiera looks up data by following a hierarchy — an ordered list of data sources. Hierarchies are configured in a hiera.yaml configuration file. Each level of the hierarchy tells Hiera how to access some kind of data source. A hierarchy is usually organized like this:

What is the use of hierarchy in SQL?

Use hierarchyidas a data type to create tables with a hierarchical structure, or to describe the hierarchical structure of data that is stored in another location. Use the hierarchyid functionsin Transact-SQL to query and manage hierarchical data. Key Properties of hierarchyid


2 Answers

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
like image 132
Schtolc Avatar answered Sep 17 '22 13:09

Schtolc


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
like image 20
Tombart Avatar answered Sep 21 '22 13:09

Tombart