We're currently arguing^w discussing the use of the params class in 
conjunction with hiera lookups and we've arrived at what I think is a 
pretty good pattern. Let me explain by way of example, using the venerable 
ntp application

class ntp{
  include ::ntp::params
  Class['::ntp::params']->
  class{'::ntp::install':}->
  class{'::ntp::config':}~>
  class{'::ntp::service':}->
  class{'::ntp::firewall':}->
  Class['::Ntp']
}

class ntp::params(
  $servers,
  $package_ensure = 'present',
  $service_ensure = 'running',
  $service_enable = true,
) {
  # os-specific stuff could go in here
  $packages = ['ntp']
  $service_name = 'ntpd'
  $config_file = '/etc/ntp/ntpd.conf'
}

class ntp::install{
  include ::ntp::params
  package{$::ntp::params::packages:
    ensure => $::ntp::params::package_ensure,
  }
}

class ntp::config{
  include ::ntp::params
  # explicitly declare any vars used in the template
  $servers = $::ntp::params::servers
  file{$::ntp::params::config_file":
    content => template(...)
  }
}

class ntp::service{
  include ::ntp::params
  service{$::ntp::params::service_name":
    ensure => $::ntp::params::service_ensure,
    enable => $::ntp::params::service_enable",
  }
}

class ntp::firewall{
  include ::ntp::params
  # firewall definition in here
}

The basic approach is that all user-changeable values are passed in via the 
params class. This class should be instantiated before the ntp class.
Typically, this class would be used in a profile class something like this:

class profile_ntp(
  $servers,
) {
  class{'::ntp::params':
    servers => $servers,
  }->
  class{'::ntp'}
}

Alternatively, $servers could come from an explicit hiera lookup:

class profile_ntp{
  class{'::ntp::params':
    servers => hiera('ntp::servers')
  }->
  class{'::ntp'}
}

The hiera key would of course be profile_ntp::servers

I can't decide whether I prefer the explicit lookup or the automatic 
approach.

I'd be interested to hear any feedback on this approach.

R.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/8d0b5ce0-fb3c-4091-bd91-e4791a993616%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to