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

What is the best practice for configuration of puppet modules? I have puppet 2.7.11. I find this way quite messy, it looks like using global variables.

node default {
   $always_apt_update = true
   include apt

Should I create class which would inherit most of configuration from the original? The documentation seems to have too many versions and I'm not sure which one applies for me.


when I try this:

  class { 'apt': 
    always_update => 'true',

I get an error:

Error 400 on SERVER: Invalid parameter always_update at /etc/puppet/manifests/nodes.pp:32
share|improve this question

3 Answers 3

up vote 3 down vote accepted

You should use Parametrized classes instead of global variables.

For example:

node default {
  class {'apt': 
    always_update =>true 
class apt ($always_update = true ) {
  // code 

node '' { 
  class { bar: }

See puppet documentation for more information:

share|improve this answer
yeah, that's what I was trying, but for 2.7 the syntax is slightly different: class { 'apt': always_update => true } – Tombart Mar 7 '13 at 12:14
I've upgraded to puppet 3.1.0, if I you exactly your code I get this: Could not parse for environment production: Syntax error at '='; expected '}'. Without parameters it works, but does not solve anything. – Tombart Mar 10 '13 at 11:29
edited post to reflect puppet 3 syntax – Kristaps Mar 11 '13 at 3:59
I had there also error in declaration of that class, now it finally works. thanks! – Tombart Mar 16 '13 at 13:53

The recommended practice these days is to use Hiera. It's built into 3.x, but in 2.7 you need to install it separately.

You can then grab data from Hiera in your manifest for the apt class:

$always_apt_update = hiera("always_apt_update")

With a Hiera config like this..

  - %{::clientcert}
  - common

..the node (pulled from the clientcert fact) will be used as higher precedence in the lookup than the common.yaml file.

So, with always_apt_update: false in and always_apt_update: true in common.yaml, node1 will end up with that variable set to false while other nodes will have it default to true.

share|improve this answer
Thanks, it looks interesting. Puppet is obviously going through rapid development and sometimes it's not clear what's the currently supported way. – Tombart Mar 10 '13 at 11:52

These answers seems a bit outdated, with new versions of puppet i.e 3.7.x, class parameters can be passed using Hiera. Resource like class declaration is not considered best practice anymore.

Although the second answer does use Hiera, but it is using ‘hiera’ function explicitly, which is again a not so advisable practice.

The new solution would look something like this:


node default {
    include apt


class apt ($always_update = true ) {
  // code 


apt::always_update: true

Hiera data yaml files can have different values of the parameter as required.

share|improve this answer
What would the hiera file name be in this example case? – Felipe Alvarez Jul 25 at 3:42

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.