In the message dated: Tue, 27 Sep 2016 13:38:16 -0400, The pithy ruminations from Christopher Wood on <Re: [Puppet Users] Moment of duhh.... Trying to wrap my head around some condi tion statements.> were: => This is one of the first custom facts I wrote, you would likely want to improve on it based on the guide. However it has worked for us for a few years now. Enjoy? => => This lives in inventory/lib/facter/hpsrl.rb. => => => if FileTest.exists?("/usr/sbin/dmidecode") => => # Add remove things to query here => query = { => 'HP ProLiant System/Rack Locator' => [ => 'Rack Name:', => 'Enclosure Name:', => 'Enclosure Model:', => 'Enclosure Serial:', => 'Enclosure Bays:', => 'Server Bay:', => 'Bays Filled:', => ] => } => => # Run dmidecode only once => output=%x{/usr/sbin/dmidecode 2>/dev/null} => => query.each_pair do |key,v| => v.each do |value| => output.split("Handle").each do |line| => if line =~ /#{key}/ and line =~ /#{value} (\w.*)\n*./ => result = $1 => result = result.gsub(/ *$/, '').gsub(/^ */, '') => Facter.add(value.chomp(':').gsub(/ /, '_')) do => confine :kernel => :linux => setcode do => result => end
I don't really (or, "really don't") do Ruby, but it looks to me like that sets the facts using the original case of the data returned from dmidecode. Maybe this is OK when creating facts by calling Facter.add(), and maybe this is OK for certain versions of puppet. I'm using puppet 3.8, and setting facts via a shell script that returns strings (see below for a heavily abridged example). In this case, the variable names _must_ begin with a lower-case letter. https://tickets.puppetlabs.com/browse/FACT-777 --------------------------------------------- #! /bin/bash # # return hardware "facts" for use by facter & puppet # # since these facts are specific to particular modules (ie. setting IPMI parameters), # we choose to store the script that generates the facts with the module that consumes # those facts, as in: # # $PUPPETHOME/environments/computenode/modules/ipmi/facts.d/ipmi_facts which dmidecode 1> /dev/null 2>&1 if [ $? != 0 ] ; then echo dmidecode=MISSING exit else echo dmidecode=INSTALLED fi # Does this machine have an IPMI device? dmidecode | grep -q ^IPMI if [ $? = 0 ] ; then if [ -c /dev/ipmi0 ] ; then ipmi=true fi fi --------------------------------------------- => end => end => end => end => end => end => => -- Mark -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/29256-1475002757.850308%40OpxQ.RGhU.3HbK. For more options, visit https://groups.google.com/d/optout.