While I’m yet to find the holy grail of getting a KVM host to be aware of which ‘dom0’ its being hosted on, this bit of ruby for a custom puppet facts is a step there, the other way around:
One question we get asked at wrk a good bit centers around finding compute resources that match a specific set of specifications.Since the compute system we haev are of all sort of various ages and hardware types, jobs that need 8GB of memory might not work everywhere, but most places.Same goes for a specific number of cores (or, minimal #), per node. Some have 4, some have 12+.
Well, facter, and therefore puppet, knows about these things. And there is a REST api we can query. And I needed an excuse to do a little ruby:
#!/usr/bin/env rubyrequire'yaml'require'puppet'puts"Welcome to the Compute Finder script!"puts"This script aims to help you locate compute nodes based on simple requirements"puts"Such as the minimum amount of RAM or # of processor cores"puts"---"puts"---"puts"What minimum amount of ram would you like?"puts"(in GB, leave blank for no minimum)"mem=gets.chompputs"What minimum number of processor cores would you like?"puts"(leave blank for no minimum)"procs=gets.chompsleep1search="facts.compute_node=true"ifmem!=""search<<"&facts.memorysize.ge=#{mem}"endifprocs!=""search<<"&facts.processorcount.ge=#{procs}"endif(procs==""andmem=="")puts"You must specify some requirments!"exitendpuppet_base="https://puppet:8140"path="/production/facts_search/search?"puts"Finding matching nodes, please wait..."cmd="curl -s -k -H \"Accept: yaml\"\"#{puppet_base}#{path}#{search}\""ans=%x[#{cmd}]nodes=YAML::load(ans)nodearr=[]nodes.sort.eachdo|node|nodearr.push(node)endputsnodearrputs"Would you like more info on the nodes found? This may take bit longer..."puts"(y/n)"more=gets.chompifmore=="y"node_array=[]nodes.eachdo|node|node_url="https://puppet:8140/production/facts/#{node}"node_cmd="curl -s -k -H \"Accept: yaml\"#{node_url}"node_ans=%x[#{node_cmd}]node_array<<YAML::load(node_ans)endresults=[]node_array.eachdo|node|name=node.namefacts=node.valuesram=facts['memorysize']procs=facts['processorcount']results.push("Host: #{name} RAM: #{ram} ProcessorCores: #{procs}")endresults.sort!putsresultsend
The output of which looks like:
1234567891011121314151617181920212223
Welcome to the Compute Finder script!
This script aims to help you locate compute nodes based on simple requirements
Such as the minimum amount of RAM or # of processor cores
---
---
What minimum amount of ram would you like?
(in GB, leave blank for no minimum)
64
What minimum number of processor cores would you like?
(leave blank for no minimum)
12
Finding matching nodes, please wait...
node01.local
node02.local
node03.local
node04.local
Would you like more info on the nodes found? This may take bit longer...
(y/n)
y
Host: node01.local RAM: 94.28 GB ProcessorCores: 12
Host: node02.local RAM: 94.28 GB ProcessorCores: 12
Host: node03.local RAM: 86.39 GB ProcessorCores: 12
Host: node04.local RAM: 251.89 GB ProcessorCores: 32
So, obviously,we use puppet a great deal. One thing a few of us have wanted for a while was the ability to ssee that nodes/node groups would be affected by a change to a particular class. In other words, what hosts get $This class?
Now, nodes are aware what classes they get, but the puppet master seemingly is not, not really. It compiles teh catalog on a per-run basis, and while durring that it DOES know what classes a system gets, it doesn’t really store that info. So, a simple custom fact to pull that data in from each host:
#list puppet classes, on per factrequire'facter'IO.popen('cat /var/lib/puppet/classes.txt | tail -n+3').readlines.eachdo|line|Facter.add("puppet_class_#{line}")dosetcodedo"true"endendend
So, now we get, for each host, a bunch of facts like:
1
puppet_class_syslog => true
Reported from facter -p, and therefor sent back to teh puppet master, into a DB, which we can query directly, via teh puppet api, or via Foreman.