You can do everything you need entirely in ruby. For example, here's a
custom fact that returns the number of screens reported by the X server.
Facter.add(:screen_count) do
confine :kernel => 'Linux'
setcode do
@screens = Facter::Core::Execution.exec("/usr/bin/xrandr -display
:0").split("\n")
@screens.count { |x| x =~ /connected/ }
end
end
Note that this only counts screens currently in use by X which may not
match the graphics card's total capabilities. A second option would be to
look at /sys/class/drm directly for any devices detected by the kernel.
For example:
Facter.add(:screen_count2) do
> confine :kernel => 'Linux'
> setcode "ls -d /sys/class/drm/*-DP-* | /usr/bin/wc -w"
> end
On Wednesday, March 22, 2017 at 6:25:10 PM UTC-4, Warron French wrote:
>
> Hello, I have finally learned how to write a Custom Fact; and duplicated
> the syntax several times over inside the same .rb file.
>
> I am using syntax that looks like the following:
>
> Facter.add('qty_monitors_total') do
> setcode do
> Facter::Util::Resolution.exec('/bin/grep " connected"
> /var/log/Xorg.0.log | cut -d\) -f2,3,4 | grep GPU |sort -u | wc -l')
> end
> end
>
> I don't know of any other way to do this yet; but that's not my concern
> yet.
>
> What I would like to know is how can I use an awk command within the
> Facter::Util::Resolution.exec('.........') line.
>
> I have a need to essentially reproduce the line above *but drop wc -l
> and add awk '{ print $2"_"$3"_on_"$1$4 }'*
>
> I need the awk command to pretty much look like this; the problem is awk
> uses its own single quotes (') and it will break the ruby code.
>
> I am not a ruby developer; so if someone could either tell me:
>
> 1. It's just not possible; or
> 2. *do it this way*
>
>
> That would be greatly appreciated. Thank you,
> --------------------------
> Warron French
>
>
--
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/8097a0bc-5709-45c8-a140-3a673b68dd31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.