Update: I can get it to return all of the output of lspci, but can't filter
it for the string I'm looking for. Example:
setcode do
controllers = []
if Facter::Util::Resolution.which('lspci')
if Facter::Util::Resolution.which('grep')
output = Facter::Util::Resolution.exec(%q{lspci|grep -iP
"VGA\s+compatible\s+controller"})
unless output.nil?
output.gsub!(/(\W)/, " ").gsub!(/\s+/," ")
end
end
end
.
.
I know the 'lspci|grep' works in the shell, but it doesn't in Ruby
If I do it to go through each line in the ouput, splitting on newlines, I
get nothing (I've left off the search and replace for now):
setcode do
controllers = []
if Facter::Util::Resolution.which('lspci')
if Facter::Util::Resolution.which('grep')
output = Facter::Util::Resolution.exec('lspci')
output.split.each {|s|
if s =~ /VGA\s+compatible\s+controller/
controllers << s
end
}
end
controllers.join(',')
end
end
On Friday, 6 January 2017 11:11:16 UTC, Cam Mac wrote:
>
> Hi Garrett,
>
> During a Puppet run, I can see it modifying the local copy of the
> videocard.rb on the client, when I've modified it. It just doesn't set the
> fact.
> I'll try Facter::Util::Resolution and see if that gets any better results.
>
> Thanks,
>
> Cam
>
>
>
> On Friday, 6 January 2017 01:59:42 UTC, Garrett Honeycutt wrote:
>>
>> On 1/5/17 6:27 AM, Cam Mac wrote:
>> > Hi,
>> >
>> > I'm trying to get videocard information into facter for installation of
>> > drivers. I've been able to
>> > get to the point of getting it to work in ruby, but not in Puppet. One
>> > thing I need to do is
>> > remove non-word characters, such as brackets, hash symbols, etc, as I
>> > run a grep command
>> > in my Puppet manifest which doesn't work when certain special
>> characters
>> > are present (apart from a comma).
>> >
>> > This is what I have so far:
>> >
>> > require 'facter'
>> >
>> > Facter.add("videocard") do
>> > confine :kernel => :linux
>> > ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
>> > setcode do
>> > ctrl = []
>> > lspciexists = system "/bin/bash -c 'which lspci >&/dev/null'"
>> > if $?.exitstatus == 0
>> > output = %x{lspci}
>> > output.split("\n").each {|s|
>> > if s =~ /VGA\s+compatible\s+controller/
>> > s.gsub!(/(\W)/, " ").gsub!(/\s+/," ")
>> > ctrl << s
>> > end
>> > }
>> > end
>> > controllers.join(',')
>> > end
>> > end
>> >
>> > What am I doing wrong here?
>> >
>> > Thanks for any help,
>> >
>> > -Cam
>> >
>>
>> Hi Cam,
>>
>> I have not tested the above code, though you say it works in Ruby and
>> not Puppet, so guessing you have an issue with where the code is on disk
>> or missing some steps in the process.
>>
>> Ensure that this code is in
>> $modulepath:/<module>/lib/facter/videocard.rb. You can remove the
>> 'require facter' line. Then run the puppet agent so that pluginsync puts
>> the code in the right place. Now run `facter -p videocard` and you
>> should see your output.
>>
>> Here's an example[1] of a module with a fact that is similar to what you
>> are doing. Notice it uses Facter::Util::Resolution.which instead of
>> system.
>>
>> Here's an example[2] of how to write unit tests for your new fact.
>>
>> [1] -
>>
>> https://github.com/ghoneycutt/puppet-module-ssh/blob/master/lib/facter/ssh.rb
>>
>>
>> [2] -
>>
>> https://github.com/ghoneycutt/puppet-module-ssh/blob/master/spec/unit/facter/ssh_spec.rb
>>
>>
>> Best regards,
>> -g
>>
>> --
>> Garrett Honeycutt
>> @learnpuppet
>> Puppet Training with LearnPuppet.com
>> Mobile: +1.206.414.8658
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/853d2526-69ec-4427-99e2-b370d1eedac5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.