Version 5 (modified by plazonic, 14 years ago) (diff) |
---|
Facter Tweaks
New facts testing
While you are writing new facts please refer to puppetlabs documentation. In short do something like:
$ mkdir -p ~/lib/ruby/facter ; export RUBYLIB=~/lib/ruby $ cp /path/to/hardware_platform.rb $RUBYLIB/facter $ facter hardware_platform SUNW,Sun-Blade-1500
New facts distributing
To distribute your new facts to puppet clients make a module (preferably the one where you are using this fact), e.g.
$ mkdir -p /etc/puppet/modules/myfirst_module/lib/facter cp myfirstfact.rb /etc/puppet/modules/myfirst_module/lib/facter
If you are distributing facts this way you can test them on the client by setting FACTERLIB environment variable:
export FACTERLIB=/var/lib/puppet/lib/facter facter
videocard fact
This ruby snippet adds a videocard fact to facter. You can use this fact to decide if you need to install any proprietary video card drivers. Place in /usr/lib/ruby/site_ruby/1.8/facter/videocard.rb
# Josko Plazonic - lifted from Josko March 14, 2011 by Thomas Uphill require 'facter' Facter.add("videocard") do confine :kernel => :linux ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin" setcode do controllers = [] lspciexists = system "/bin/bash -c 'which lspci >&/dev//null'" if $?.exitstatus == 0 output = %x{lspci} output.each {|s| controllers.push($1) if s =~ /VGA compatible controller: (.*)/ } end controllers end end
After installing you should be able to see the fact like so:
[root@host ~]# facter |grep video videocard => Intel Corporation 82945G/GZ Integrated Graphics Controller (rev 02) [root@host ~]#
Kernel versions fact
This fact requires rubygem ruby-rpm. Either install it from source or if you are using a RHEL 6 based distro (like PUIAS 6 or any other clone) please feel free to use the relevant rpm from our unsupported repo (rubygem-ruby-rpm-1.3.0-* from repository):
require 'rubygems' require 'rpm' begin Facter.architecture rescue Facter.loadfacts() end db = RPMdb.open() allkernels=db.package("kernel").collect { |x| RPM::Version.new(x[1]+"-"+x[2]) }.sort db.close() Facter.add("kernelnewest") do confine :kernel => :linux setcode do allkernels[-1].v+"-"+allkernels[-1].r+"."+Facter.architecture end end Facter.add("kerneloldest") do confine :kernel => :linux setcode do allkernels[0].v+"-"+allkernels[0].r+"."+Facter.architecture end end
This fact provides kernelnewest and kerneloldest facts. They can be used, together with kernelrelease fact, in puppet recipes to figure out whether the puppet client is currently running the latest kernel version as well as whether there are alternate versions of the kernel installed. Example recipes that use this module will be posted on the puppet recipes page.