Puppet&Hiera: $variable is not an hash or array when accessing it
Posted
by
txworking
on Server Fault
See other posts from Server Fault
or by txworking
Published on 2013-06-28T08:43:11Z
Indexed on
2013/06/28
10:23 UTC
Read the original article
Hit count: 323
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:
classes:
- install
common_instances:
- common_instance_1
- common_instance_2
common_instanceconfig:
common_instance_1
path : '/opt/common_instance_1'
version : 1.0
files : software-1.bin
pre : pre_install.sh
after : after_install.sh
properties: "properties"
common_instance_2:
path : '/opt/common_instance_2'
version : 2.0
files : software-2.bin
pre : pre_install.sh
after : after_install.sh
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?
© Server Fault or respective owner