How to use custom facts with Vagrant/puppet-apply?

asked 2015-01-20 18:03:57 -0500

oep gravatar image

I have a custom fact to try and guess what kind of graphics card is on the system.

Facter.add(:graphicscardtype) do
  confine :kernel => 'Linux'
  setcode do
    # Attempt to use lspci to get the PCI vendor of device class 0300.
    cmd = '/usr/bin/lspci -m -n'
    cmd += ' | /bin/egrep ^.{9}0300'
    cmd += " | /usr/bin/cut -d ' ' -f 3"
    vendor = Facter::Core::Execution.exec(cmd)
    if vendor == nil
      vendor = ''

    # Remove quotes from either end.
    vendor = vendor.chomp('"').reverse.chomp('"').reverse

    case vendor
    when '10de'

It seems to work fine when setting $FACTERLIB and using facter directly, both in the positive and negative case:

$> facter graphicscardtype

This fact lives in a module I'm writing in nvidia/lib/facter/graphicscardtype.rb. I am testing it on a Vagrant virtual machine which uses puppet apply. My module has a snippet like so

if $::graphicscardtype != 'nvidia' {
  notify { "Skipping graphics card type ${::graphicscardtype}": }

but my notice looks like this:

Notice: Skipping graphics card type

I expected the '???' to show up there, so it makes me think my fact isn't getting used, but clearly Puppet is discovering it:

Info: Loading facts in /vagrant/dist/nvidia/lib/facter/graphicscardtype.rb

This is my puppet.conf

confdir = /etc/puppet
modulepath = /etc/puppet/modules:/vagrant/dist:/vagrant/site
logdir = /var/log/puppet
vardir = /var/lib/puppet
rundir = /var/run/puppet
ssldir = /var/lib/puppet/ssl
pluginsync = true

pluginsync = true

I think I've goofed up somewhere but not sure where. Should I fix my fact, configuration, or is there something wrong with the way I'm using Vagrant?

edit retag flag offensive close merge delete