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 end end end end end end On Tue, Sep 27, 2016 at 08:38:00AM -0700, Scott Walker wrote: > Ahh perfect there is.. Now onto the next battle.. figuring out how to use > it lol. > > On Monday, 26 September 2016 18:39:45 UTC-4, Nick Miller wrote: > > Hey Scott, > > You probably want to reference a Fact, whether custom or not. Check > `puppet facts find $(hostname)` to see what facts are available on your > systems. If you don't find on you like, you may have to write one > following [1]this guide. It should be fairly easy to make a dmidecode > fact if there isn't one already. > > Good luck, > Nick > On Mon, Sep 26, 2016 at 6:09 PM, Scott Walker > <[2]cri...@unspeakable.org> wrote: > > I'm relatively new to puppet (came from chef world). > > I'm trying to figure out a way to cleanly do the following... > > On machines which /usr/sbin/dmidecode | grep Z640 (this is how we are > sure the machine is Z640 and not some other type of machine) return > true I want to do the following: > > file { '/etc/default/grub': > path => '/etc/default/grub' > ensure => present, > mode => '0644', > owner => 'root', > group => 'root', > notify => Exec['grub-update'], > source => 'puppet:///modules/z640/grub' > } > > exec { 'grub-update': > refreshonly => true, > command => '/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg', > } > > Otherwise I don't want to do anything. (This is to help fix an NVME > issue I am having on 60+ workstation out of 700 in the studio. > > I just can't wrap my head around a clean way to achieve this goal. > > I know this is probably a really simple task I just need some > direction.... > > -- > 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 [3]puppet-users...@googlegroups.com. > To view this discussion on the web visit > > [4]https://groups.google.com/d/msgid/puppet-users/024553d2-1872-4eab-9bd5-8280c92c07ec%40googlegroups.com. > For more options, visit [5]https://groups.google.com/d/optout. > > -- > > Nicholas Miller > Consultant | Onyx Point, Inc. > > [6]OnyxPoint-logo-symbol-primary.png 7050 Hi Tech Drive, Suite 102 > > Hanover, MD. 21076 > e: [7]nick....@onyxpoint.com > w: 443-655-3675 > [8]copmany.png[9]careers.png[10]product.png[11]meetups.png[12]blog.png > > -- > 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 [13]puppet-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > > [14]https://groups.google.com/d/msgid/puppet-users/3c190210-fa30-48f2-8d18-4835c54cfe53%40googlegroups.com. > For more options, visit [15]https://groups.google.com/d/optout. > > References > > Visible links > 1. https://docs.puppet.com/facter/3.4/custom_facts.html > 2. javascript: > 3. javascript: > 4. > https://groups.google.com/d/msgid/puppet-users/024553d2-1872-4eab-9bd5-8280c92c07ec%40googlegroups.com?utm_medium=email&utm_source=footer > 5. https://groups.google.com/d/optout > 7. javascript: > 13. mailto:puppet-users+unsubscr...@googlegroups.com > 14. > https://groups.google.com/d/msgid/puppet-users/3c190210-fa30-48f2-8d18-4835c54cfe53%40googlegroups.com?utm_medium=email&utm_source=footer > 15. https://groups.google.com/d/optout -- 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/20160927173816.GA12939%40iniquitous.heresiarch.ca. For more options, visit https://groups.google.com/d/optout.