home

Puppet - profiles with support of different module versions

17 Aug 2016

At Globalways we are using the profile / roles layout for our puppet infrastructure.

The profiles are shared all over our different customer environments - so we have one place for our profiles.

This is a good solution until you need to support different module versions. But with Puppet future parser it is getting better.

Our example is the tomcat module from PuppetLabs. With the version 1.5.0 there is new option 'manage_service'.

The code before supporting 1.5.0 looks like:

# install and prepare default tomcat instance
tomcat::instance { 'default7':
  package_name   => 'tomcat7',
  catalina_home  => '/var/lib/tomcat7',
  package_ensure => $package_ensure,
}

If the environment is using version 1.5.0 or greater the manage_service option should be false for our needs.

$metadata = load_module_metadata('tomcat', true)
if (versioncmp($metadata['version'], '1.5.0') >= 0) {
  $tomcat_options = {
    'manage_service' => false,
  }
}
else {
  $tomcat_options = {}
}
# install and prepare default tomcat instance
tomcat::instance { 'default7':
  package_name   => 'tomcat7',
  catalina_home  => '/var/lib/tomcat7',
  package_ensure => $package_ensure,
  *              => $tomcat_options,
}

We are reading the module version with the stdlib function and then using a future parser option, to use a hash as options for the define.

We are now able to support more versions of the tomcat module within one profile.