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 chXXX-M through chXXX-N
    # from renke in #ruby

    pe2650_list = (1..5).map{|_| "ch226-#{_}"}
    pe1850_list = (6..7).map{|_| "ch226-#{_}"}
    pe1850_cee_list = (8..8).map{|_| "ch226-#{_}"}
    pe1855_che_list = (11..19).map{|_| "ch226-#{_}"}
    sc1435_list = (21..32).map{|_| "ch226-#{_}"}
    ch405_list = (1..14).map{|_| "ch405-#{_}"}
    ch406_list = (1..14).map{|_| "ch406-#{_}"}
    ch409_list = (1..14).map{|_| "ch409-#{_}"}

    # Map short hostname ranges to queues.
    result = "unknown"

    if result=="unknown" and pe2650_list.include?(output):
        result = "pe2650"
    elsif result=="unknown" and pe1850_list.include?(output):
        result = "pe1850"
    elsif result=="unknown" and pe1850_cee_list.include?(output):
        result = "pe1850-cee"
    elsif result=="unknown" and pe1855_che_list.include?(output):
        result = "pe1855-che"
    elsif result=="unknown" and sc1435_list.include?(output):
        result = "sc1435"
    elsif result=="unknown" and ch405_list.include?(output):
        result = "ch405"
    elsif result=="unknown" and ch406_list.include?(output):
        result = "ch406"
    elsif result=="unknown" and ch409_list.include?(output):
        result = "ch409"
    end

    result
  end
end