Nvidia driver install - condition for install

852 views
Skip to first unread message

Mike Reed

unread,
Jun 29, 2012, 2:29:57 PM6/29/12
to puppet...@googlegroups.com
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

Dan White

unread,
Jun 29, 2012, 3:23:13 PM6/29/12
to puppet...@googlegroups.com
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.

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

Nan Liu

unread,
Jun 29, 2012, 3:49:46 PM6/29/12
to puppet...@googlegroups.com
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

Peter Bukowinski

unread,
Jun 29, 2012, 4:31:21 PM6/29/12
to puppet...@googlegroups.com
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

Tim Mooney

unread,
Jun 29, 2012, 5:10:31 PM6/29/12
to puppet...@googlegroups.com
In regard to: [Puppet Users] Nvidia driver install - condition for install,...:

> 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" : }
>
> }

First, you probably want to set up an explicit ordering relation between
the file and the exec. Otherwise, you're relying on ordering that may
work, but only by chance.

> 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.

Right. The exec will fire every time. The way to fix this is to use
one of the attributes for exec. Most likely candidates are

unless => "some command here"

or

onlyif => "some command here"

Read the resource guide for exec and note that those two have opposite
senses.

Note that you probably *don't* want to use notify from the file and
refreshonly on the exec, because the file may get downloaded
semi-regularly (because it was cleaned from /tmp) but you don't want
the exec to fire every time the file is (re)downloaded.

The trick is finding the right command that can be used in the unless or
onlyif. That amounts to being able to determine, via some (potentially
compound) command, whether or not the driver is installed. So how do you
do that? Does it show up in an RPM list? Is there a /dev file that's
created? An area that exists in the /proc or /sys filesystem?

Let's pretend for the purposes of example that when the driver is loaded,
there's a /sys/device/class/graphics/nvidia directory that's created. If
that's the case, you could make your class look like

class nvidia_driver {

# This will place the nvidia installer locally in /tmp. File is
# pulled from puppet.

# if you have hiera, it would be even better to use it:
# $driver_version = hiera('nvidia_driver_version', 'fallback version here')
# might want to abstract the architecture too...
$driver_version = '295.53'

file { "/tmp/NVIDIA-Linux-x86_64-${driver_version}.run" :
source => "puppet:///modules/nvidia_driver/NVIDIA-Linux-x86_64-${driver_version}.run" ,
ensure => present ,
}

# This will run the nvidia installer locally on the machine.
exec { 'install_nvidia_driver':
cmd => "/tmp/NVIDIA-Linux-x86_64-${driver_version}.run -s -X --opengl-headers --no-distro-scripts --force-tls-compat32=new",
unless => 'test -d /sys/device/class/graphics/nvidia',
}

File["/tmp/NVIDIA-Linux-x86_64-${driver_version}.run"] ->
Exec['install_nvidia_driver']

}

Be advised that's untested.

> 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.

What I'm describing would still have the file resource fire every time
/tmp gets cleaned and you need to re-download the driver, but it wouldn't
cause the exec to happen unless then driver was detectable as not
available.

The real trick is detecting whether or not the driver is installed. Once
you figure out how to do that, the rest just falls into place.

Tim
--
Tim Mooney Tim.M...@ndsu.edu
Enterprise Computing & Infrastructure 701-231-1076 (Voice)
Room 242-J6, IACC Building 701-231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

jcbollinger

unread,
Jul 2, 2012, 9:12:48 AM7/2/12
to puppet...@googlegroups.com


On Friday, June 29, 2012 1:29:57 PM UTC-5, Mike Reed 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:
 
[...]

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.  


Every assigned class "runs" every Puppet run.  That's Puppet's nature.  Running does not necessarily imply making any changes (which for Exec's means running the specified command), but all resources assigned to the node will at least check whether they are already in the correct state.  For Execs, that nature of those checks is governed by the 'unless', 'onlyif'', and 'creates' parameters.

I suggest you look for a pre-built driver package (RPM, DEB, etc.) for your systems.  For the RHEL family of Linuxes, for instance, you can find such packages in the elrepo and atrpms repositories.  Add the appropriate repository to your system (perhaps via a Yumrepo resource), and manage the driver via a Package resource.

If there is no pre-built package for your particular systems then consider creating one and putting it in your own local repository.  Managing packages is better in every way than managing installers.


John

James A. Peltier

unread,
Jul 4, 2012, 12:46:56 AM7/4/12
to puppet...@googlegroups.com
Check to see if an nVidia module already exists for the current kernel and if not build

if [ ! -e /lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ]; then


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



--
James A. Peltier
Manager, IT Services - Research Computing Group
Simon Fraser University - Burnaby Campus
Phone   : 778-782-6573
Fax     : 778-782-3045
E-Mail  : jpel...@sfu.ca
Website : http://www.sfu.ca/itservices
          http://blogs.sfu.ca/people/jpeltier

Success is to be measured not so much by the position that one has reached
in life but as by the obstacles they have overcome. - Booker T. Washington

Mike Reed

unread,
Jul 5, 2012, 1:42:12 PM7/5/12
to puppet...@googlegroups.com
Hey All,

I got moved onto another project and I hadn't been able to get back to this one until today.  I first wanted to thank you all for the information and suggestions.  I'll take a look and see what I can do and I'll be sure to let everybody know what the outcome is. 

I like Nan's suggestion about a custom fact but I'm not quite there in my knowledge yet so I suspect I'll use some mix of a relation and a simple "if" statement.

Cheers,

Mike
Reply all
Reply to author
Forward
0 new messages