1

I am new to ruby and am trying to get a puppet custom fact to work. Here is the code for the custom fact:

Facter.add("mounts") do
  confine :osfamily => "RedHat"
  setcode do
    mountlist=""
    #Facter::Core::Execution.exec('/bin/mount | /bin/cut -f3 -d" "')
    #mounts=`/bin/mount`
    mounts = Facter::Core::Execution.exec('/bin/mount')

    mounts.each_line do |line|
      fs=line.match(/^[^\s]+\s+on\s(.+) type.+/).captures
      mountlist=mountlist + fs.to_s + ","
    end
    mountlist
  end
end

The idea of the code is to create a custom fact called mounts, which can then be used in a manifest for a module. Here is one of the stanzas from the manifest file:

if ("/tmp" in $mounts) {
  mount{'tmpfs_mnt':
    name     => "/tmp",
    options  => [ 'nodev','nosuid','noexec' ],
    ensure   => present,
    atboot   => true,
    fstype   => tmpfs,
    remounts => true,
  }
}

The custom fact does not appear to get created. Here is the output from one of the puppet nodes when trying to pull this module:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: 'undef' from right operand of 'in' expression is not of a supported type (string, array or hash)

Any help on what corrections are needed to get the custom fact working would be greatly appreciated.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
user3155618
  • 359
  • 1
  • 5
  • 14
  • SOLVED: The custom fact code is fine, it was the location of the code that was the problem. Once I moved the code from ~/lib/ruby/facter to ~/lib/facter it worked. – user3155618 Jan 16 '17 at 18:38
  • 2
    Actually, you should place the fact in `module/lib/facter/`. That will work universally. – Matthew Schuchard Jan 17 '17 at 12:21

0 Answers0