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