Writing your own facter code - puppet
Puppet agent provides a set of ruby codes and that stay at /usr/lib/ruby/site_ruby/1.8/facter/*.rb. These ruby codes are the one that provides values for facter's output.
[root@test ~]# facter -p
architecture => x86_64
augeasversion => 0.9.0
boardmanufacturer => Intel Corporation
boardproductname => 440BX Desktop Reference Platform
boardserialnumber => None
domain => houston.hp.com
facterversion => 1.6.6
fqdn =>test.hiu.com
hardwareisa => x86_64
hardwaremodel => x86_64
hostname => d9t0578g
id => root
If you stand on the $rubysitedir, /usr/lib/ruby/site_ruby/1.8, you will notice that you can addon more ruby codes to define your own facter parameter and values.
[root@test facter]# pwd
/usr/lib/ruby/site_ruby/1.8/facter
[root@d9t0578g facter]# ls
application.rb kernel.rb puppetversion.rb
architecture.rb kernelrelease.rb qpk.rb
arp.rb kernelversion.rb rawpartition.rb
augeasversion.rb lsbmajdistrelease.rb rubysitedir.rb
Cfkey.rb lsb.rb rubyversion.rb
domain.rb macaddress.rb selinux.rb
ec2.rb macosx.rb ssh.rb
facterversion.rb manufacturer.rb timezone.rb
fqdn.rb memory.rb uniqueid.rb
hardwareisa.rb netmask.rb uptime_days.rb
hardwaremodel.rb network.rb uptime_hours.rb
hostname.rb operatingsystem.rb uptime.rb
id.rb operatingsystemrelease.rb uptime_seconds.rb
interfaces.rb osfamily.rb util
ipaddress6.rb path.rb virtual.rb
ipaddress.rb physicalprocessorcount.rb vlans.rb
iphostnumber.rb processor.rb xendomains.rb
kernelmajversion.rb ps.rb
This is how i wrote my simple facter codes, called raw_partition.
[root@test facter]# cat rawpartition.rb
# Fact: checking the QPK version
Facter.add(:raw_partition) do
setcode do
confine :kernel => :linux
Facter::Util::Resolution.exec("cat /proc/partitions | awk '/sd/ {print $4}' | sed -e 's|sd|/dev/sd|g' | grep -v sda")
end
end
Basically, you can alter the line that i highlighted and put some meaningful shell script/strings to yield a different output.
The output of this will be like below.
[root@test facter]# facter -p
architecture => x86_64
augeasversion => 0.9.0
boardmanufacturer => Intel Corporation
boardproductname => 440BX Desktop Reference Platform
boardserialnumber => None
.
.
.
raw_partition => /dev/sdd
/dev/sdc
/dev/sdb
No comments:
Post a Comment