4

How can I include module with parameters when inheriting node default. Is it possible?

For now, I've removed "inherits default" and changed it to node server123 { //include that //include this }. But then whenever I make changes to default, I'll have to make the same change to node server123.

I wonder if I should change ntp module to workaround this?

File: manifest/nodes.pp

node default {
  include ssh 
  include ntp
  ruby::install { "1.2.3-456": } 
  nagios { "1.2.3-456": }
}

node 'server123' inherits default {
 class { 'ntp':     ntpserver => 'true' } -> duplicate class defined error.
 ## I want to define  "$ntpserver = 'true'" here, so it doesn't inherit ntp client config.
 ## I've tried other methods too, but none of them work.
}

File: modules/ntp/init.pp

class ntp ($ntpserver = "false") {
  //erb parameters
} 

if $ntpserver == 'true' { 
  //case $OS
  //code for ntpserver template 
} else { 
  //case $OS
  //code for ntp.conf template  
}
  • 2
    Is there a reason why you don't go with hiera? You can define a default, and also on a per-node basis, the per-node definition has a higher priority over the default. – mzhaase Nov 16 '16 at 7:49
1

Puppet 4 does not support node inheritance, however you rewrite your code using "traits" classes (or directly using class{'something':}). You example could be rewritten into:

class base_node {
  include ssh 
  include ntp
  ruby::install { "1.2.3-456": } 
  nagios { "1.2.3-456": }
}

node /^server\d+/ {
  require base_node
}

More fancy solution might use your custom module, nothing complicated just modules/base/manifests/linux.pp:

class base::linux {
  ...
}

Even more complex rules can be creating using Hiera, where node definition is very simple:

node /^server\d+/ {
  hiera_include('classes')
}

and rest of logic is in YAML hierarchy:

# common.yaml
---
classes:
  - ntp

# Debian.yaml
---
classes:
  - base::linux
  - localrepos::apt

assuming some hierachy in hiera.yaml:

:hierarchy:
  - "%{::fqdn}"
  - "%{::osfamily}"
  - common

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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