Ask Your Question

Revision history [back]

Unfortunately, when you are using Hiera automatic parameter lookup, as you are doing (same as example given on the module documentation page), Puppet only uses the "priority" matching scheme to retrieve data. It loads the data from the first file in the hierarchy, instead of merging data found from all levels in the hierarchy.

See: https://docs.puppetlabs.com/hiera/1/puppet.html#limitations

You can work around that limitation by changing your linux_default class like so:

class linux_default {
  class { 'accounts':
    groups => hiera_hash('accounts::groups', {})
  }

  include motd
}

NOTE: The 2nd parameter of the hiera_hash function is a default value (empty hash) that will be returned in case the key lookup fails for some reason.

All that modification does is override the automatic parameter lookup for the groups attribute with a value of your choice. Note that you should remove the class { 'accounts': } line above in site.pp, as it's declaring the accounts class with default parameters, and it will conflict with the new declaration I have written above.

I guess if you want to always declare the class using the hiera_hash function, you can move that declaration outside of the node { ... } directives like so:

# This class will be declared for all nodes because it appears at the global level in 
# site.pp. It may be a good candidate for wrapping with another class and placing
# in a module elsewhere in the Puppet code hierarchy.
class { 'accounts':
  groups => hiera_hash('accounts::groups', {})
}

# This is a good candidate for placing in a module elsewhere in the Puppet code hierarchy
class motd {
   file { '/etc/motd':
     ensure  => file,
     owner   => 'root',
     group   => 'root',
     content => 'Hello world! Puppet is awesome.',
   }
 }

class linux_default {
   include motd
}

Once you start putting that much class declaration code in site.pp, though, I would start looking at building a module and following these best practices: https://docs.puppetlabs.com/guides/module_guides/bgtm.html

Hope this helps!