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  
}
1
  • 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, 2016 at 7:49

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .