Ask Your Question

fully-qualified variable fail with error ' not a hash or array when accessing it with class_name'

asked 2017-06-28 18:57:41 -0600

mazdajai gravatar image

updated 2017-06-29 10:25:37 -0600

DarylW gravatar image


I have the following modules and hiera and failed with error ' not a hash or array when accessing it with class_name' when using fully-qualified variable $foo::config::writer. If I use just $writer, it will be fine.

I think this is a scoping issue but I am not sure where is it, any thoughts?

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: foo::config::writer is not a hash or array when accessing it with class_name at /etc/puppet/environments/production/modules/foo/manifests/config.pp:10 on node Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

    class foo {
      include foo::params

  case $foo::params::application {
    'bar': {
      foo::config { 'bar':
        query_array         => [
    default: {
      foo::config { 'default':
        query_array => $foo::metrics::default_metrics,
        writer      => $foo::params::writer,
        interval    => '60',

define foo::config (
  $writer   = hiera_hash('foo::writer'),
  $interval = hiera('foo::interval', '120'),
  ) {
  include foo


  $output = {
    class      => $foo::config::writer['class'],
    attributes => $foo::config::writer['attributes'],

foo::queries: ''
    class: 'class2'
      fileName: '/tmp/zoo'
      showTimeStamp: 'false'
foo::interval: '60'
edit retag flag offensive close merge delete


Wouldn't you call the vairable just by isuing $writer. I think maybe the problmem is that it tri's to look up by hiera and will look for the $foo::config::writer but under your yaml you only have foo::writer?

negast gravatar imagenegast ( 2017-06-29 00:42:41 -0600 )edit

As far as I know, line 10 is not doing a lookup it should just accessing the array defined on line 2...?

mazdajai gravatar imagemazdajai ( 2017-06-30 10:18:12 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-03 08:39:31 -0600

Henrik Lindberg gravatar image

You cannot access a parameter of a user defined resource type like that. The variable $foo::config::writer is not a reference to the parameter $writer for the define foo::config. It is most likely undef, and if you had --strict_variables turned on, puppet would error.

Try to make the initialization cleaner by using a class and automatic parameter lookup (APL). Use a class as the entry point - include it and set its parameters using APL. Make it use different defines based on conditional logic. It is much easier to reason about the logic when values are given to classes/functions/etc than when they are trying to pull in values. Also avoid using variable references to variables inside if classes (that is also pulling in a value). The "pull-in" style will make you end up with a large spaghetti mess.

If you are on puppet 4 or 5, use hiera 5 and place the default values in hiera in your module.

edit flag offensive delete link more


I think I am still a bit confused because `$writer` works. I thought this is a scoping issue - `$foo::config::writer` is global scope while `$writer` is local scope. Am I missing something?

mazdajai gravatar imagemazdajai ( 2017-07-03 15:59:44 -0600 )edit

>Also avoid using variable references to variables inside if classes (that is also pulling in a value) We are on puppet 3.8.7 and we have been been using 'this' to pull hiera, is there documentation to better do this? Thanks!

mazdajai gravatar imagemazdajai ( 2017-07-03 16:01:32 -0600 )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: 2017-06-28 18:57:41 -0600

Seen: 94 times

Last updated: Jul 03 '17