Servermanagement with puppet – Part 4
Puppet facts
Note: This article based on Part 1 – Part 3 of my puppet articles. Please read them first !
Factor allows to you add information from your nodes to your puppet configuration.
Facts are available as variables. Execute the “facter” command and you get a full list of facts an their values:
sebastian@pc1:~$ facter architecture => i386 domain => domain.local facterversion => 1.5.1 fqdn => pc1.domain.local hardwaremodel => i686 hostname => pc1 interfaces => eth0 ipaddress => 192.168.0.2 ipaddress_eth0 => 192.168.0.2 kernel => Linux kernelrelease => 2.6.28-11-server kernelversion => 2.6.28 lsbdistcodename => jaunty lsbdistdescription => Ubuntu 9.04 lsbdistid => Ubuntu lsbdistrelease => 9.04 macaddress => 00:0c:29:7a:37:37 macaddress_eth0 => 00:0c:29:7a:37:37 memoryfree => 417.25 MB memorysize => 497.37 MB netmask => 255.255.255.0 netmask_eth0 => 255.255.255.0 operatingsystem => Ubuntu operatingsystemrelease => 9.04 processor0 => Intel(R) Xeon(TM) CPU 2.80GHz processorcount => 1 ps => ps -ef puppetversion => 0.24.5 rubysitedir => /usr/local/lib/site_ruby/1.8 rubyversion => 1.8.7 swapfree => 883.99 MB swapsize => 883.99 MB virtual => vmware
You see that my “pc1″ is a 32-Bit virtual machine with Ubuntu 9.04. Now we want to extend our “baseclass template” to install the vmware-tools on all virtual machines.
Edit “/etc/puppet/manifests/templates.pp”:
#
# templates.pp
#
class baseclass {
include user::admins
include munin::client
include ntp
if $virtual == "vmware" {
include vmware::client
}
case $virtual {
vmware: { include vmware::client }
}
}
Create vmware module:
mkdir -p /etc/puppet/modules/vmware/manifests/
Create “/etc/puppet/modules/vmware/manifests/init.pp” file:
#
# init.pp
#
class vmware{
}
Create “/etc/puppet/modules/vmware/manifests/client.pp” file:
#
# client.pp
#
class vmware::client inherits vmware{
package { open-vm-tools: ensure => installed }
}
Note: This is a simple example. If you have more than one operating system in your environment, you need the “operatingsystem” variable for a second condition.
http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#conditionals
Custom Facts
You can also define your own facts in puppet.
http://reductivelabs.com/trac/puppet/wiki/AddingFacts

