Can anyone point me to a "Writing Puppet recipes for Dummies" doc? I''m trying to do a basic probe using lspci to see if I have a Qlogic HBA installed on the machine, and if so, install the Qlogic scli package. Here''s a shell script of what I''m trying to do: #!/bin/bash vendor=1077 # QLogic model=2422 # 24xx hba /sbin/lspci -n -d $vendor:$model | grep $vendor | grep $model > /dev/null if [ $? = 0 ] then # Install package fi I believe I need to write a define that does an exec with the $vendor and $model passed to it through a class: define fc_hba($vendor,$model) { exec { "probe_hba": command => "/sbin/lspci -n -d $vendor:$model | grep $vendor | grep $model > /dev/null" } } class install_fc_hba_software { fc_hba { vendor => 1700, model => 2422, # install correct package here? } } I''m not clear on how to pass the result of the define back to the class or if it''s even possible. Help is greatly appreciated, Jeff
On 6/8/2007 2:52 PM, Jeff Falgout wrote:> I''m trying to do a basic probe using lspci to see if I have a Qlogic > HBA installed on the machine, and if so, install the Qlogic scli > package.It may be overkill, but there''s a Facter/Puppet recipe (http://www.reductivelabs.com/trac/puppet/wiki/VirtualRecipe) that detects whether or not you''re running puppetd under one of a few different virtual machine environments. Adapting it to detect your HBA should be relatively easy (completely untested, and I don''t know Ruby well at all, so I''m not positive that the %x call will work unquoted, etc.): ### Facter fact Facter.add("qlogichba") do confine :kernel => :linux ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin" result = "absent" setcode do lspciexists = system "which lspci >&/dev/null" if $?.exitstatus == 0 output = %x{lspci -n -d 1077:2422} output.each {|p| # --- look for the QLogic HBA result = "present" if p =~ /1077:2422/ } end result end end ### Puppet manifest class qlogichba { package { "scli": ensure => $qlogichba ? { present => installed, absent => absent } } } -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
On 6/8/07, Mike Renfro <renfro@tntech.edu> wrote:> On 6/8/2007 2:52 PM, Jeff Falgout wrote: > > I''m trying to do a basic probe using lspci to see if I have a Qlogic > > HBA installed on the machine, and if so, install the Qlogic scli > > package. > > It may be overkill, but there''s a Facter/Puppet recipe > (http://www.reductivelabs.com/trac/puppet/wiki/VirtualRecipe) that > detects whether or not you''re running puppetd under one of a few > different virtual machine environments. Adapting it to detect your HBA > should be relatively easy (completely untested, and I don''t know Ruby > well at all, so I''m not positive that the %x call will work unquoted, etc.): > > ### Facter factSo a custom fact is really the best way to do it - That was my last excuse for not sitting now and going down the ruby road. . . Thanks for the fact - I''ll give a shot a report back. Jeff
> > So a custom fact is really the best way to do it - That was my last > excuse for not sitting now and going down the ruby road. . . > > Thanks for the fact - I''ll give a shot a report back. >I''m in the middle of building up a set of facts and some management functions to install and manage appropriate RAID management utilities under linux. This seems to be a related area, so probably worth consolodating. I''ll put my code up on the wiki once I get it close to useful and remember my login details. I''m currently working on the facts to expose the appropriate information, and while it''s not particularly elegant, it does part of the job. In the meantime, here''s what I have for providing a fact about which RAID controller you might have: eg: # This basically searches the output of lspci for any ''RAID bus controller'' entries and pushes the # tail end of that string into a fact. I''m sure this will get messy with multiple controllers in the same # system, so needs work Facter.add("raidcontroller") do confine :kernel => :linux ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin" setcode do controllers = [] lspciexists = system "/bin/bash -c ''which lspci>&/dev//null''"if $?.exitstatus == 0 output = %x{lspci} output.each {|s| controllers.push($1) if s =~ /RAID bus controller: (.*)/ } end controllers end end
> > > > It may be overkill, but there''s a Facter/Puppet recipe > > (http://www.reductivelabs.com/trac/puppet/wiki/VirtualRecipe) that > > detects whether or not you''re running puppetd under one of a few > > different virtual machine environments. Adapting it to detect your HBA > > should be relatively easy (completely untested, and I don''t know Ruby > > well at all, so I''m not positive that the %x call will work unquoted, etc.): > > > > ### Facter fact > > So a custom fact is really the best way to do it - That was my last > excuse for not sitting now and going down the ruby road. . . > > Thanks for the fact - I''ll give a shot a report back. >This works as expected! Thanks
On 6/8/07, Daniel Lawson <daniel@meta.net.nz> wrote:> I''m in the middle of building up a set of facts and some management > functions to install and manage appropriate RAID management utilities > under linux. This seems to be a related area, so probably worth > consolodating. I''ll put my code up on the wiki once I get it close to > useful and remember my login details. I''m currently working on the > facts to expose the appropriate information, and while it''s not > particularly elegant, it does part of the job. In the meantime, here''s > what I have for providing a fact about which RAID controller you might have: > > eg: > > # This basically searches the output of lspci for any ''RAID bus > controller'' entries and pushes the > # tail end of that string into a fact. I''m sure this will get messy > with multiple controllers in the same > # system, so needs work > Facter.add("raidcontroller") do > confine :kernel => :linux > ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin" > setcode do > controllers = [] > lspciexists = system "/bin/bash -c ''which lspci > >&/dev//null''" > if $?.exitstatus == 0 > output = %x{lspci} > output.each {|s| > controllers.push($1) if s =~ /RAID bus > controller: (.*)/ > } > end > controllers > end > end > >Great - I''ll keep an eye out for it. . . . How would it handle multiple raid controllers on the same host? Like multiple processors? If so, how would you write a recipe that loops through each controller to see if the vendor/model match your criteria? Jeff