How to detect NVIDIA GPU with Puppet

Solution 1:

You should create a custom fact that either checks the existence of /usr/bin/nvidia-smi (if that's sufficient), with something like:

Facter.add(:nvidia_gpu) do
  confine :kernel => 'Linux'
  setcode do
    FileTest.executable?('/usr/bin/nvidia-smi')
  end
end

or perhaps to be more thorough checks to see if a particular PCI device exists, if it shows up as one, using either the output of lspci or walking the /sys/bus/pci directory.

In your Puppet manifests, you can then use the value of $facts['nvidia_gpu'] to control what you do.