Tuesday, September 19, 2017

Subject: Puppet conditionals on custom facts
======================================================================

I was getting Puppet to error out like a shell script is a challenge.  My favorite solution to date is creating a custom fact in a module's "lib/facter" sub directory.  Although there are other solutions, most involve a modicum of ruby coding.

To get Puppet to error out if /sys/kernel/mm/transparent_hugepage
exists, I had to create a custom fact. 

/opt/puppetlabs/code/environment/production/oradbms/modules/linode3/lib/facter/trans_huge_frame.rb
   Facter.add(:linode3_transparent_hugepagedo
      setcode do
      if File.exist? '/sys/kernel/mm/transparent_hugepage'
         '/sys/kernel/mm/transparent_hugepage'
      else
         if File.exist? '/sys/kernel/mm/redhat_transparent_hugepage'
            '/sys/kernel/mm/redhat_transparent_hugepage'
         else
            #DEBUG if File.exist? '/sys/kernel/mm/page_idle' # This is just a test case
            #DEBUG    '/sys/kernel/mm/page_idle'
            #DEBUG else
            #DEBUG   'absent'
            #DEBUG end
            'absent'
         end
     end
   end
end

The manifest code looks like
   if "${facts['linode3_transparent_hugepage']}" != 'absent' {
      fail("fail('ERROR: found file: ${facts['linode3_transparent_hugepage']}, meaning Transparent Huge Pages are enabled for an Oracle server, which is not allowed.")
   }

Hopefully that makes sense.

No comments:

Post a Comment