Identify a node's group by its short hostname
Fact originally identified the puppet client's Torque/PBS/etc. queue by short hostname. Can also be adapted to identify groups of HA servers or other pools of interchangeable nodes.
# hostgroup.rb
Facter.add("hostgroup") do
# Limiting to Linux, since all my cluster systems are Linux-based.
confine :kernel => :linux
setcode do
output = %x{hostname --short}.chomp
#output = "ch409-1" ### Test case
# Compact way of generating ch409-1 through ch409-14
# from renke in #ruby
ch409list = (1..14).map{|_| "ch409-#{_}"}
# Map short hostname ranges to queues. Since I don't have a
# fixed-format hostname structure for my cluster nodes, I need to
# account for the double-digit ones first. Otherwise, hostname
# "ch226-32" will fall into the range of
# "ch226-3".."ch226-5".
result = case output
when "ch226-11".."ch226-19":
"pe1855-che"
when "ch226-21".."ch226-32":
"sc1435"
when "ch226-3".."ch226-5":
"pe2650"
when "ch226-6".."ch226-7":
"pe1850"
when "ch226-8":
"pe1850-cee"
when "ch405a".."ch405n":
"ch405"
when "ch406a".."ch406n":
"ch406"
else "unknown"
end
if result=="unknown" and ch409list.include?(output):
result = "ch409"
end
result
end
end