Ask Your Question
0

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 http://docs.puppetlabs.com/hiera/1/co... .

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
["vmwaretools"]
[root@puppet3 puppet]# facter virtual
vmware

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 puppet3.example.org 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 http://docs.puppetlabs.com/hiera/1/complete_example.html

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

/etc/puppet/hieradata/common.yaml :

---

classes:
  - ntp
  - motd
  - stefan-puppet
  - epel
  - users

vmwaretools::version: 8.6.5-621624

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

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

---
classes:
  - vmwaretools
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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

fvoges gravatar image

Check http://docs.puppetlabs.com/hiera/1/lo...

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: http://docs.puppetlabs.com/references/latest/function.html#hiera

From your example, I guess that you also want to check hiera_include(): http://docs.puppetlabs.com/hiera/1/puppet.html#assigning-classes-to-nodes-with-hiera-hierainclude

edit flag offensive delete link more

Comments

Yes, `hiera_array()` is what I want. `hiera --array classes` also prints an array. You can see my tests here: https://gist.github.com/stefanlasiewski/6d4db8075ffd07444709

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

Stats

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

Seen: 602 times

Last updated: Jul 03 '14