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
}
Best Answer
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:More fancy solution might use your custom module, nothing complicated just
modules/base/manifests/linux.pp
:Even more complex rules can be creating using Hiera, where node definition is very simple:
and rest of logic is in YAML hierarchy:
assuming some hierachy in
hiera.yaml
: