Hello all,

I'm working with a custom fact that's returning an array as it's value. 
 The fact looks like this:

require 'facter'

Facter.add(:video_card_id) do
  confine :kernel => :linux
  setcode do 
    
    # create array for card id's
    id_array = Array.new
  
    # determine id of card #
    id_query  = %q{lspci | grep -i 'vga' | awk '{print $8}'}
    id_return = Facter::Util::Resolution.exec(id_query)

    # add id's to array
    id_return.each { |id| id_array.push(id) }
    id_array.map! { |x| x.chomp }
    
    # return id array
    id_array
  end
end


Running 'facter -p' on the client side (assuming we have two video cards 
installed), I receive a result of:  video_card_id => ["17c2", "17c2"]
This result means to me that I was returned two strings, each of which are 
contained within a typical ruby'ish collection.

Now, if I try and reference the first item in the collection - like below - 
using video_card_id[0] within a puppet manifest, I get an error

notify { "Installing driver version: ({$::video_card_id[0]})" : }

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: 
::video_card_id is not a hash or array when accessing it with 0.


This fact is part of a larger design that incorporates the fact's value 
into something like this:

class nvidia::config (
  $model_hash = {
      '009d' => "$::nvidia::params::quadro_fx_4500_driver",
      '06dc' => "$::nvidia::params::quadro_6000_driver",
      '06d9' => "$::nvidia::params::quadro_5000_driver",
      '11ba' => "$::nvidia::params::quadro_K5000_driver",
      '17c2' => "$::nvidia::params::gtx_titanx_driver",
      '17f0' => "$::nvidia::params::quadro_M6000_driver",
  }

) inherits nvidia::params {

  if ($::is_virtual == true) and ($::class == 'server') {
    notify { 'This is a virtual machine and the nvidia driver doesn\'t get 
intalled' : 
  }
    
    # only run nvidia installer if the machine is a workstation and the 
driver is not already installed
  } elsif ($::class == 'workstation') and ($::nvidia_installed == false ) { 
   
        # let 'em know what you're doing
        notify { "Installing driver version: 
${model_hash[$::video_card_id[0]]}" : }
        
        # stop kde before driver install
        exec { 'kdm-stop' :
          command => '/usr/bin/service kdm stop',
          unless  => '/usr/bin/service kdm status | grep -i "stop" ',
          before  => Exec['nvidia-driver-install'],
        }
        
        # install nvidia driver
        exec { 'nvidia-driver-install' :
          command => "/usr/src/{$model_hash[$::video_card_id[0]]}.run -s -X 
-N --force-tls=new --no-x-check --no-cc-version-check",
          require => 
File["/usr/src/${model_hash[$::video_card_id[0]]}.run"],
          notify  => Exec['reboot_after_nvidia'],
        }
        
        # reboot after nvidia install
        exec { 'reboot_after_nvidia' :
          command     => "/sbin/reboot",
          refreshonly => true,
        } 
    }
}

I've done quite a bit of reading around this but can't quite figure out 
what I'm doing wrong.  When testing my array indexing via Ruby, things work 
fine so my thought is that this is a DSL thing that I've missed.  I've done 
some reading around future parser but I don't understand it enough to tell 
if that's my problem.  

If anybody could help shed some light on this one, I'd be most grateful. 
 This is similar to another of my posts', with the exception that before I 
wasn't using an array as a fact's value and thus, I'm quite confused.   
(Old Post: 
 https://groups.google.com/forum/#!topic/puppet-users/1ol4b1euTiE)

Both server and client are running:  Puppet 3.6.2/Facter 2.1.0

Thank you in advance for your help.

Cheers,

Mike



-- 
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/03753d71-b1c8-495e-8155-8b2be10526b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to