On Jun 29, 2012, at 3:49 PM, Nan Liu wrote:

> On Fri, Jun 29, 2012 at 12:23 PM, Dan White <y...@comcast.net> wrote:
>> ----- Mike Reed <mjohn.r...@gmail.com> wrote:
>>> Hello all,
>>> 
>>> I'd like to use puppet to install an Nvidia driver on a local workstation.
>>>  I've written the following manifest for this puprpose:
>>> 
>>> class nvidia_driver {
>>>         # This will place the nvidia installer locally in /tmp.  File is
>>> pulled from puppet.
>>>         file { "/tmp/NVIDIA-Linux-x86_64-295.53.run" :
>>>                 source  =>
>>> "puppet:///modules/nvidia_driver/NVIDIA-Linux-x86_64-295.53.run" ,
>>>                 ensure  => present ,
>>>         }
>>> 
>>>         # This will run the nvidia installer locally on the machine.
>>>         exec { "/tmp/NVIDIA-Linux-x86_64-295.53.run -s -X --opengl-headers
>>> --no-distro-scripts --force-tls-compat32=new" :  }
>>> 
>>> }
>>> 
>>> Upon the initial run of the manifest on the target machine, everything
>>> works great (although I do believe there is some room for improvement of
>>> the code above; particularly on the exec portion) and the driver then gets
>>> installed.  The issue occurs on subsequent puppet runs on the same machine
>>> and I'm getting the following error during my second puppet run from the
>>> client:
>>> 
>>> err: /Stage[main]/Nvidia_driver/Exec[/tmp/NVIDIA-Linux-x86_64-295.53.run -s
>>> -X --opengl-headers --no-distro-scripts --force-tls-compat32=new]/returns:
>>> change from notrun to 0 failed: /tmp/NVIDIA-Linux-x86_64-295.53.run -s -X
>>> --opengl-headers --no-distro-scripts --force-tls-compat32=new returned 1
>>> instead of one of [0] at
>>> /etc/puppet/modules/nvidia_driver/manifests/init.pp:12
>>> 
>>> It appears to me that the above error is occurring because the
>>> nvidia_driver class is running on each subsequent run and since the driver
>>> is already installed, I'm getting an exit status of 1 instead of 0, which
>>> to my knowledge would be expected.
>>> 
>>> So, what I'd like to do is put some sort of condition that will look to see
>>> if the driver is installed and if it is, the class "nvidia_driver" won't
>>> run.  I'm having a hard time figuring this one out and I was hoping to get
>>> a few opinions on how this might be accomplished.
>>> 
>>> Would this potentially be a job for a shell script that does the checking?
>>>  Maybe just adding the shell script into the "nvidia_driver" manifest?
>>> 
>>> Thanks in advance for everybody's assistance and the help is very much
>>> appreciated.
>>> 
>>> Cheers,
>>> 
>>> Mike
>> 
>> I am working with the same kind of drivers and I have a suggestion:
>> 
>> The driver only needs to be re-installed when the kernel changes version.
>> 
>> I am not sure how to implement this idea, but it is something to check 
>> against.
>> If I have any revelations, I will post here.
> 
> Seems like a custom fact to detect nvidia driver version is the most
> sensible thing since it will also alleviate the need to download the
> binary file in the first place.
> 
> Nan

I use a couple custom facts to handle video cards and driver versions.

This fact will return the vendor for all video cards installed in the machine. 
Each card actually gets its own fact named videocard[n], where n starts at 0.
- - - - -
# videocards.rb                                                                 
                                                                                
      

controllers = []
output = %x{lspci}
output.each {|s|
    controllers.push($1) if s =~ /VGA compatible controller: (.*)/
}

for vc in 0...controllers.length
    thecard = "videocard" + vc.to_s
    Facter.add(thecard) do
        setcode do
            controllers[vc]
        end
    end
end
- - - - -

This fact gets the driver version for the first video card only. (This 
restriction makes sense in my environment. It might not in yours.) The if 
statement is necessary to allow for the presence and/or success (some cards 
don't work with it) of the nvidia-smi tool.
- - - - -
# nvidiadriver.rb                                                               
                                                                                
       

Facter.add("nvidiadriver") do
    setcode do
        if Facter.value(:videocard0) =~ /nVidia/
            smitest = %x{/usr/bin/nvidia-smi -q}.chomp
            if smitest.empty?
                %x{awk -F'Driver  ' '/X Driver/{print $2}' /var/log/Xorg.0.log 
| awk '{print $1}'}
            elsif smitest.match(/^nvidia-smi/)
                %x{awk -F'Driver  ' '/X Driver/{print $2}' /var/log/Xorg.0.log 
| awk '{print $1}'}
            else
                %x{/usr/bin/nvidia-smi -q -x -i 0 | awk -F'>' 
'/driver_version/{gsub("</.*$","");print $2}'}
            end
        elsif Facter.value(:videocard0) =~ /ATI|AMD/
            %x{yum list installed xorg-x11-drv-catalyst.x86_64 | awk 
'/catalyst/{print $2}'}
        end
    end
end
- - - - -

I use the nvidiadriver fact to restrict where my nvidia driver class runs, e.g.

class nv_driver {
    if ! ( $nvidiadriver == '295.59' ) {
        file { '/root/NVIDIA-Linux-x86_64-295.59.run':                          
                                            
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
            source  => 'puppet:///files/nvidia/NVIDIA-Linux-x86_64-295.59.run',
            notify  => Exec['install-nvidia-295.59'],
        }
        exec { 'install-nvidia-295.59':
            command     => '/root/NVIDIA-Linux-x86_64-295.59.run -s -X',
            refreshonly => true,
        }
    }
}


--
Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to