IPv6 address facts in older versions of facter

Facter is a companion tool to the puppet configuration management system that allows you to retrieve metadata about the system puppet is running on. This is then made available to puppet for use in config file templates or making informed decisions on how to go about configuring a system.

One thing I noticed when going through the list of variables output by facter was that no IPv6 address information was being reported. This was a bit of a roadblock as the majority of our systems are dual-stacked (IPv4 and IPv6), with many configuration files needing to know what IPv6 addresses to listen on. Whilst an ipaddress6 fact was added to facter 1.59, I’m working with a somewhat older version of Puppet (0.25) and Facter (1.56), these both ship with Ubuntu 10.04 LTS so I’d rather stick with them if at all possible, rather than resorting to a backports repository.

Luckily, the puppet guide provided a quick solution – custom facts. It was a simple matter of grabbing the relevant code from github and dropping it into a directory in the $FACTERLIB path. Running the facter command will now print out an ipaddress6 variable:

 $ facter ipaddress6
 2001:6f8:900:909::2

Of course, this only makes the fact available to the environment you are testing on. If you are running a puppetmaster server, you’ll need to follow the guide to distributing plugins as modules if you want to distribute the fact around your network. This can be done on a per-module basis, or globally as a top-scope variable by creating a skeleton module with a blank init.pp and the ipaddress6.rb file in the lib/facter directory.

To test if the variable is available, add the following to your site.pp manifest on the puppetmaster server:

 class puppet_v6_marker {
      file {
            '/tmp/puppet-v6':
            ensure => present,
            mode   => 600,
            owner  => root,
            content => $::ipaddress6,
            group  => root
      }
}

include puppet_v6_marker

Your puppet clients should now output their IPv6 address to /tmp/puppet-v6.