Archive

Posts Tagged ‘versioncmp’

Puppet: package installation based on OS version

August 13th, 2012 No comments

If you want to handle a package installation based on the operating system version, you can use versioncmp function.

$result = versioncmp(a, b)

This functions returns a number:
* > 0 if version a is greater than version b
* == 0 if both version are equals
* < 0 if version a is less than version b

Example:

[cce_bash]  'Debian'     :  {       $ver = versioncmp($operatingsystemrelease,0)
            if $ver < 6.0 {
      package { 'nsca': ensure => present }
            } else {
      package { 'nsca': ensure => '2.7.2+nmu2' }
            }
    }[/cce]