Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have mixture of CentOS , 5.8, 5.7, 6.1, 6.3 , 4.7 Ubuntu, Debian, servers with me. I want all of them to have nrpe installed on them. the problem i am facing is that when i write puppet code to ensure the packe nrpe, it works fine on Centos 6+ , but when it runs on centos 5.8, the package name there is nrpe-nagio, and not nrpe.. I tried to do this in this way, but unable to perform the required checks.

package { "nrpe":
    ensure => "installed",
        name => $operatingsystem ? {
   Ubuntu => "nagios-nrpe-server",
   CentOS => "nrpe",
{
/^5/: {
package { "nagios-nrpe":
    ensure => "installed", }
        }
}

   Debian => "nagios-nrpe-server",
    }
}

How can i have nested checks for what i need?

thanks

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Inline, nested case statements are a bad way to do this, and it's actively discouraged in Puppet (see Puppet Lint documentation).

The better way is this (I've guessed with $::lsbdistrelease as I don't have a RH system to-hand - you should run facter to determine the correct fact that gives you the major version).

$nrpe_package = $::osfamily ? {
  'Debian' => 'nagios-nrpe-server'
  'RedHat' => $::lsbdistrelease ? {
    '5'     => 'nagios-nrpe',
    default => 'nrpe',
  }
  default => 'nrpe',
}

package { 'nrpe':
  ensure => installed,
  name   => $nrpe_package,
}

Explanation (links to Puppet Lint where appropriate):

share|improve this answer
add comment

You can use facter and some if/else conditions to tell Puppet which class you want to apply to each version of CentOS.

Example : http://docs.puppetlabs.com/learning/variables.html#case

(Just use your OS version instead of the OS in the example provided).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.