Facter: ismaster

This is a Facter rule I created to determine if the local host is the Puppet Master.

Their may have been a better way to do this; but this appears to work okay.

NOTE: If you've got a better way to do this, please email me at "tom dot sandholm at gmail dot com"

NOTE: This only works with webbrick

I'm just checking for the existance of /var/run/puppet/master.pid.

This file is created when the puppetmaster runs on a node.

The facter rule will return either "true" or "false" based on whether puppetmaster is running there.

Here is a sample output:

<On the puppetmaster>:

beast3:~ # ssh -Y root@puppet

Linux puppet 2.6.32-5-amd64 #1 SMP Wed Jan 12 03:40:32 UTC 2011 x86_64

The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

Last login: Thu Mar 10 09:53:10 2011 from beast3.tsand.org

root@puppet:~# facter | grep ismaster

ismaster => true

root@puppet:~#

<On a non-puppetmaster node>:

beast3:~ # ssh -Y root@n1

Linux n1 2.6.32-5-amd64 #1 SMP Wed Jan 12 03:40:32 UTC 2011 x86_64

The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

Last login: Thu Mar 10 10:04:15 2011 from beast3.tsand.org

root@n1:~# facter | grep ismaster

ismaster => false

root@n1:~#

Here is the code:

# /usr/lib/ruby/1.8/facter/ismaster.rb

# vi:set nu ai ap aw smd showmatch tabstop=4 shiftwidth=4:

# determine if this host is puppet master

Facter.add("ismaster") do

setcode do

if FileTest.exists?("/var/run/puppet/master.pid")

true

else

false

end

end

end