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/8c8b33b0-35ab-507b-ffc2-02ee48f73b48%40garretthoneycutt.com.
For more options, visit https://groups.google.com/d/optout.