Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was using Puppet 3.2.2 and Hiera 1.2.1. And I wrote a puppet module and the content of init.pp was:

class install(
  $common_instanceconfig = hiera_hash('common_instanceconfig'),
  $common_instances = hiera('common_instances')

  define instances {

    common { $title:
      name       => $title,
      path       => $common_instanceconfig[$title]['path'],
      version    => $common_instanceconfig[$title]['version'],
      files      => $common_instanceconfig[$title]['files'],
      pre        => $common_instanceconfig[$title]['pre'],
      after      => $common_instanceconfig[$title]['after'],
      properties => $common_instanceconfig[$title]['properties'],
      require    => $common_instanceconfig[$title]['require'] ,


  instances {$common_instances:}

And the hieradata file was:

  - install

  - common_instance_1
  - common_instance_2

    path      : '/opt/common_instance_1'
    version   : 1.0
    files     : software-1.bin
    pre       :
    after     :
    properties: "properties"

    path      : '/opt/common_instance_2'
    version   : 2.0
    files     : software-2.bin
    pre       :
    after     :
    properties: "properties"

I always got a error message When puppet agent run

Error: common_instanceconfig String is not an hash or array when accessing it with common_instance_1 at /etc/puppet/modules/install/manifests/init.pp:16 on node puppet.agent1.tmp

It seems $common_instances can be got correctly, but $commono_instanceconfig always be treated as a string.

I used YAML.load_file to load the hieradata file, and got a correct hash object.

Can anybody help?

share|improve this question
Which line is line 16? – Shane Madden Jun 30 '13 at 1:54
Hi, @ShaneMadden. I update the question, so former line 16 was path => $common_instanceconfig[$title]['path'],. – txworking Jul 1 '13 at 2:12
@ShaneMadden Finally I found this was a variable scope problem. In the scope of define type instances $common_instanceconfig could not be accessed. So there should be a parameter to do it. – txworking Jul 1 '13 at 6:47

Even I faced the same problem with nested hashes. I had to write code to make nginx vhosts.This is my YAML file

 - host1
 - host2

        hostname: "one"
        docroot: "england"
        php_fpm: 2097
        db_name: "noidea"
        db_passwd: "sheeit"

        hostname: "two"
        docroot: "nagaland"
        php_fpm: 3000
        db_name: "awesm"
        db_passwd: "pisss"

And this is my manifest

$vhost_array = hiera_array("vhost_array")

define hash_extract(){
                $vhost_hash = hiera_hash("vhost_hash")
                $vhost = $vhost_hash[$name]     ## TRICK lies in $name variable


$name is the variable that gets values from array, and those values are being used to access the hashes.You can find more info about $name variable here

share|improve this answer
up vote 3 down vote accepted

Finally I found this was a variable scope problem, the correct init.pp should be:

class install(
  $common_instances = hiera_array('common_instances'),
  $common_instanceconfig = hiera_array('common_instanceconfigs'),
  define instances (
  ) {   

  common { $common_instances[0]: 
    name       => $title,
    path       => $common_instanceconfig[0],
    version    => $common_instanceconfig[1],
    files      => $common_instanceconfig[2],
    pre        => $common_instanceconfig[3],
    after      => $common_instanceconfig[4],
    properties => $common_instanceconfig[5],
    require    => $common_instanceconfig[$title]['require'] ,

  instances {$common_instances: 
    common_instanceconfig => $common_instanceconfig

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.