Select Page
NOTE: This is a static archive of an old blog, no interactions like search or categories are current.

There has been many discussions about Facter 2, one of the things I looked forward to getting was the ability to read arbitrary files or run arbitrary scripts in a directory to create facts.

This is pretty important as a lot of the typical users just aren’t Ruby coders and really all they want is to trivially add some facts. All too often the answer to common questions in the Puppet user groups ends up being “add a fact” but when they look at adding facts its just way too daunting.

Sadly as of today Facter 2 is mostly vaporware so I created a quick – really quick – fact that reads the directory /etc/facts.d and parse Text, JSON or YAML files but can also run any executable in there.

To write a fact in a shell script that reads /etc/sysconfig/kernel on a RedHat machine and names the default kernel package name simply do this:

#!/bin/sh
 
source /etc/sysconfig/kernel
 
echo "default_kernel=${DEFAULTKERNEL}"

Add it to /etc/facts.d and make it executable, now you can simple use your new fact:

% facter default_kernel
kernel-xen

Simple stuff. You can get the fact on my GitHub and deploy it using the standard method.