Ask Your Question

Why doesn't hiera append the 'vmware' classs to my classes array? ?

asked 2014-07-02 20:11:38 -0500

updated 2014-07-03 12:57:44 -0500

I'm trying to understand how Hiera merges arrays. I following the example at .

When I ask Hiera to print the classes array, I get the array that I set in common.yaml, which is what I would expect. But if I explicitly set a key=value pair, Hiera replaces the array with one element. I was expecting Hiera to print something like ["ntp", "motd", "stefan-puppet", "epel", "users","vmwaretools"], but instead I simply get ["vmwaretools"].

[root@puppet3 puppet]# hiera classes
["ntp", "motd", "stefan-puppet", "epel", "users"]

Here, Hiera prints a single-element array:

[root@puppet3 puppet]# hiera classes ::virtual=vmware
[root@puppet3 puppet]# facter virtual

And if I call Hiera from Puppet. it still prints only a single-element array:

[root@puppet3 puppet]# puppet apply -e '$somevar = hiera("classes") notify { $somevar: }'
Notice: Compiled catalog for in environment production in 0.03 seconds
Notice: vmwaretools
Notice: /Stage[main]/Main/Notify[vmwaretools]/message: defined 'message' as 'vmwaretools'
Notice: Finished catalog run in 0.04 seconds
[root@puppet3 puppet]#

Here is my Hiera environment, which I believe is fairly typical.

/etc/puppet/hiera.yaml :

# /etc/puppet/hiera.yaml
# borrowed from

  - yaml
  :datadir: /etc/puppet/hieradata
  - "nodes/%{::clientcert}"
  - "environment/%{::environment}"
  - "virtual/%{::virtual}"
  - "osfamily/%{::osfamily}"
  - common

/etc/puppet/hieradata/common.yaml :


  - ntp
  - motd
  - stefan-puppet
  - epel
  - users

vmwaretools::version: 8.6.5-621624

ntp::autoupdate: true
ntp::enable: true

/etc/puppet/hieradata/virtual/vmware.yaml :

  - vmwaretools
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-03 06:25:41 -0500

fvoges gravatar image


hiera() only returns the first match. To merge the values from different levels, you have to use hiera_array().

There's a bit more info here too:

From your example, I guess that you also want to check hiera_include():

edit flag offensive delete link more


Yes, `hiera_array()` is what I want. `hiera --array classes` also prints an array. You can see my tests here:

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-03 13:12:59 -0500 )edit

In my `site.pp`, I am using `hiera_include('classes')`. If I didn't, `puppet apply -e` wouldn't print the Hiera classes at all.

stefanlasiewski gravatar imagestefanlasiewski ( 2014-07-03 13:16:19 -0500 )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: 2014-07-02 20:11:38 -0500

Seen: 654 times

Last updated: Jul 03 '14