Software Engineer

package version as fact in puppet

· by jsnby · Read in about 1 min · (106 Words)

Let’s say that you wanted to have a puppet fact that contained the version number of a particular package installed on each server. For this example, let’s use the nagios’ nrpe package. I put my custom facts into a <modulepath>/custom/lib/facter/, so I’ll call it <modulepath>/custom/lib/facter/nrpe.rb. The code looks like this:

require 'facter'

result = %x{/bin/rpm -q --queryformat "%{VERSION}-%{RELEASE}" nrpe}

Facter.add('nrpe') do
    setcode do

This creates a fact called ‘nrpe’ that can be accessed in your puppet modules via $nrpe (or to be completely correct, $::nrpe). If you’re not using an RPM-based distribution, you may need to salt and pepper that command to taste.

You can find this code on github in my puppet-facts repository.