0

I'm configuring syslog-ng through puppet on my servers. The configuration files are very different between versions 2.x, 3.1 and 3.3 . On my hosts, depending on the operating system (centos5, centos6, debian 7, ubuntu), the available syslog-ng version will vary.

I had 2 ideas to adapt the configuration of syslog-ng to the correct version :

  • Custom Fact : It's easy to write a custom fact to test the installed version of syslog-ng. But this fact will be useless if syslog-ng is not already installed.
  • Conditions in the manifest : I find it a bit ugly to define a "case" in the manifest wich would determine the version of syslog-ng that the operatingsystem provides.

For me, the cleanest way to do this is to test which version of the package is available through the operatingsystem before installation. A facter could do this, but I guess it would be a bit difficult.

Is there a puppetish way to solve my problem ?

2 Answers 2

1

There is indeed puppet-ish way to solve this problem!

You can combine $::osfamily with $::operatingsystemrelease to do something like this in your manifests:

case $::osfamily {
  'CentOS': { 
    case $::operatingsystemrelease {
       /^6/: { include syslog-ng::centos6 }
       /^5/: { include syslog-ng::centos5 }
       default: { notice("This operating system release for CentOs '${::operatingsystemrelease}' is not supported.")
    }
   }
   default:  { notice "Unsupported osfamily ${::osfamily}" }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Having a subclass for each case seems clean. Though you have to know in advance wich distribution ships which version of the package, and I would have liked to avoid this knowledge.
1

I am not sure I understood all of your problem. In any case, one can use puppet package type to ensure a particular version and use $lsbdistdescription to get the OS name. For example :

package { 'syslog-ng' :
    ensure => $::lsbdistdescription {
    '/CentOS 7/': => "3.2",
    '/CentOS 6/': => "3.1",
    '/(Debian|Ubuntu)/' => "2.x",
    default => "latest",
   },
}

NOTE: In the above one has to get the exact name of the OS, i.e. CentOS 7 or CentOS 6 or Ubuntu from each OS. You can do that by executing facter --puppet | grep lsbdistdescription on the OS. I don't have variety of machines, so I couldn't check that exactly.

Then the configuration file can be just one sourced from a template. The template will vary based on the OS.

file { 'file.cfg' :
    ensure => "present",
    content => template("modulename/file.erb"),
    require => Package["syslog-ng"],
}

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.