Facter is an "independent, cross-platform Ruby library designed to gather information on all the nodes you will be managing with Puppet". Facts are bits of information on nodes (a.k.a. machines) you manage via Puppet. For example, a fact is the machine architecture (x86_64), another is the DNS domain the machine is located in (mens.de) or a list of network interfaces (eth0,eth1,lo). These facts are obtained by the facter utility and they can be used within Puppet modules.

Facter is extensible: you can (I can't) write Ruby code to gather site-specific data you want to provide as facts and distribute your code as a plug-in in a module. R.I.Pienaar created facts-dot-d for people like myself, who don't write Ruby.

I obtain the facts-dot-d plug-in and drop it into a directory I create in my module directory, say, /etc/puppet/modules/j1/lib/facter/. On the Puppet agents I ensure plug-ins are synchronized (i.e. downloaded to nodes from the Puppet master) by adding pluginsync = true to the [main] section of their puppet.conf.

At the next puppet run this plug-in is copied over to the nodes which are configured to use a class in my module.

In order to add custom facts to these nodes, I create the /etc/facts.d directory and populate that with *.txt, *.yaml, *.json or executable files. (If you prefer to store your facts in a different directory, change the default directory name on the last line of facter_dot_d.rb.)

For example, I create /etc/facts.d/jp.txt containing the following text:

manager=Jane Q. Public

I'll also create an executable program (make sure it's executable) called /etc/facts.d/temp which determines the temperature of the machine room by querying some probe or other. When the program runs it emits the following text:


At the next run of the agent, Puppet runs the Facter plug-ins and adds the key/value pairs they produce to the list of facts for the node. I can use any of these facts (e.g. location) in my classes. For a list of all facts collected on a particular node look at the /var/lib/puppet/yaml/facts/node.yaml file:

--- !ruby/object:Puppet::Node::Facts
    kernel: Linux
    kernelversion: 2.6.18
    manager: Jane Q. Public
    temperature: 24C
    operatingsystem: CentOS
    location: Chicago

Very practical.

Flattr this
Puppet and Facter :: 21 Jul 2011 :: e-mail


blog comments powered by Disqus