Re: Hiera Hash

1,220 views
Skip to first unread message

Jarod Watkins

unread,
Aug 22, 2012, 10:22:04 PM8/22/12
to puppet...@googlegroups.com
Sorry, I should explained my issue:

class apache (
  $apache = hiera_hash('apache'),
  $mpm    = $apache['mpm'],
)

This code will produce the following error:

Could not retrieve catalog from remote server: Error 400 on SERVER: apache is not an hash or array when accessing it with mpm

If I do not try to set mpm inside the class definition but inside the manifest it will work:

class apache (
  $apache = hiera_hash('apache'),
) {

  $mpm = $apache['mpm']
  notify { "Hiera is: ${mpm}": }

Again am I seeing a bug or is this not how I should be doing things?

Jarod

On Wednesday, August 22, 2012 9:39:46 PM UTC-4, Jarod Watkins wrote:
Hello,
I have the following in common.yaml:

apache:
  mpm: worker

If I do a "manual" lookup with the hiera command I get the proper result:

hiera --config /etc/puppet/hiera.yaml apache
{"mpm"=>"worker"}

However, when trying to get the apache hash in a manifest, it appears to be returned as a flattened string. I am using this notify statement in the manifest:

$apache = hiera('apache')
notify { "Hiera is: ${apache}": }

And I get this returned:

Notify[Hiera is: mpmworker]

The same thing is returned when I used hiera_hash. Interestingly enough, when I used hiera_array I get this error message:

Hiera type mismatch: expected Array and got Hash

Am I seeing some sort of bug or am I doing something wrong?

Puppet version: 2.7.18
Hiera version: 1.0.0-0.1rc4
Puppet-Hiera version: 1.0.0-0.1rc3

Thanks,
Jarod

jcbollinger

unread,
Aug 27, 2012, 2:55:46 PM8/27/12
to puppet...@googlegroups.com


On Wednesday, August 22, 2012 9:22:04 PM UTC-5, Jarod Watkins wrote:
Sorry, I should explained my issue:

class apache (
  $apache = hiera_hash('apache'),
  $mpm    = $apache['mpm'],
)

This code will produce the following error:

Could not retrieve catalog from remote server: Error 400 on SERVER: apache is not an hash or array when accessing it with mpm

If I do not try to set mpm inside the class definition but inside the manifest it will work:

class apache (
  $apache = hiera_hash('apache'),
) {

  $mpm = $apache['mpm']
  notify { "Hiera is: ${mpm}": }

Again am I seeing a bug or is this not how I should be doing things?


You should be using the plain hiera() function instead of hiera_hash().  The latter is for collecting values of the same key from multiple levels of your environment, and returning the combined result as a hash (level => value, IIRC).  You just want the value assigned to key 'apache'; that the value happens to be a hash is irrelevant.


John

Reply all
Reply to author
Forward
0 new messages