Ask Your Question

hiera command line fetch particular value

asked 2016-03-30 06:41:10 -0600

karthikeayan gravatar image

updated 2016-03-30 06:41:52 -0600

I have data in hiera like below,

  - hostname:
  - hostname:

Is it possible to get the IP Address of node through hiera command line?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-03-30 14:59:27 -0600

lavaman gravatar image

You would only be able to get the array of hashes. Hiera can't give you a data value based on another value. You can get that array of hashes in yaml or json format then select the value you need using jq or a script of some sort.

edit flag offensive delete link more

answered 2016-03-31 16:34:54 -0600

reesek gravatar image

Yes -- this is possible. I believe you need to be on at least hiera 2.0, though I tested on 3.0.3.

puppetmaster ~ # hiera --version

puppetmaster ~ # pwd

puppetmaster ~ # cat nodes.yaml 
  - hostname:
  - hostname:

puppetmaster ~ # hiera nodes.0.ipaddress environment=dev calling_module=nodes
edit flag offensive delete link more


My understanding was that he specifically wanted to query by hostname, not by array position.

lavaman gravatar imagelavaman ( 2016-03-31 17:02:32 -0600 )edit

Ah -- could be. I see your perspective to the question. Looks like you also see mine :)

reesek gravatar imagereesek ( 2016-03-31 18:00:08 -0600 )edit

Indeed. It just forces you into constraints around data ordering and whatnot. Would be fragile to rely upon for anything important.

lavaman gravatar imagelavaman ( 2016-03-31 18:16:20 -0600 )edit

Just like anything else, it likely depends on the use case. If the user is looking to populate something like /etc/hosts from that data set for example, then maybe not. Otherwise, a restructuring of the data may be needed to avoid awkward constraints as you've pointed out.

reesek gravatar imagereesek ( 2016-03-31 21:03:18 -0600 )edit

my hiera is only 1.3.4, couldn't use your command

karthikeayan gravatar imagekarthikeayan ( 2016-04-06 07:40:36 -0600 )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


Asked: 2016-03-30 06:41:10 -0600

Seen: 191 times

Last updated: Mar 31 '16