Gathering Information About a System by Using Facter
The Facter utility gathers information about a system and sends it to the Puppet Server (server) for compilation into catalogs. A catalog specifies the configuration changes to apply to a managed node.
A catalog also includes the specified state of each resource. Based on these definitions, each system can apply its own configurations, as appropriate. After you apply the catalog to the system, the Puppet Agent (agent) generates a report and sends that report to the server. This report contains information about which resources are currently being managed on the target node, as well as about any changes that have been made to the node to achieve a desired state. See How Puppet Works.
The following facter -p
command lists all of the available facts for this system:
# facter -p
architecture => i86pc
facterversion => 2.4.6
hardwareisa => i386
hardwaremodel => i86pc
hostname => myhost
id => root
interfaces => lo0,net0
ipaddress => 10.0.0.15
ipaddress6 => ::
ipaddress_lo0 => 127.0.0.1
ipaddress_net0 => 10.0.0.5
ipaddress_net1 => 10.0.1.5
...
uptime => 0:22 hours
uptime_days => 0
uptime_hours => 0
uptime_seconds => 1320
virtual => virtualbox
Or, you can display an individual fact for a given node, for example hostname
, as follows:
# facter hostname
myhost
Gathering facts about a system can help you to determine the configuration types that you can enforce on the system. For example, you could declare a file resource to populate a given file with platform-specific content.
The following example shows that the osfamily
fact declares the platform within the file:
$file_contents = $osfamily ? { 'solaris' => "Hello Oracle Solaris", 'redhat' => "Hello RHEL", } file { '/custom-file.txt': ensure => 'present', content => $file_contents, }
The previous example includes the $file_contents
variable and a conditional check based on the value of the osfamily
fact. Depending on the platform type, you would assign different contents to the file.
For more information, see the Facter documentation.