Override facts from facter

298 views
Skip to first unread message

Davide Ferrari

unread,
Jan 9, 2015, 9:48:34 AM1/9/15
to puppet...@googlegroups.com
Hi

I'm trying to override a fact from facter 2.3, called "partitions"
with a custom version of this fact, via pluginsync.

The problem is that the base file in
/var/lib/puppet/lib/facter/partitions.rb, just like it's facter
brother in /usr/lib/ruby/vendor_ruby/facter/partitions.rb has a

require 'facter/util/partitions'

and this require seems to me that, no matter what I do, try to
includes other ruby files from /usr/lib/ruby/vendor_ruby/ and not
/var/lib/puppet/lib/, even if I run facter -p.

What's the correct way to override via pluginsync an already existing
and complex fact like "partitions" ? I'm already specifying
"has_weigth 100" in /var/lib/puppet/lib/facter/partitions.rb because
otherwise it wouldn't even consider my custom version, but it stops
there.

Thanks!

Felix Frank

unread,
Jan 11, 2015, 7:04:00 PM1/11/15
to puppet...@googlegroups.com
Hi,

I've done similar things with older versions of Facter. It should work.

Can you share your code, the result, and what you expect to happen?

Thanks,
Felix

Davide Ferrari

unread,
Jan 12, 2015, 7:22:54 AM1/12/15
to puppet...@googlegroups.com
Hello!

My code is basically this commit

https://github.com/vide/facter/commit/c4060af48074c372a63409d81b836b79ff5d0427

This patch works smoothly if I overwrite the files in /usr/lib/ruby/vendor_ruby/

Then I've put those 4 files in

my_module/lib/facter/partitions.rb
my_module/lib/facter/util/partitions.rb
my_module/lib/facter/util/partitions/linux.rb
my_module/lib/facter/util/partitions/openbsd.rb

they are copied through pluginsync and they are *completely* ignored.
Then, if I add the "has_weight 100" line to
my_module/lib/facter/partitions.rb then at least I get this error

Could not retrieve fact='partitions', resolution='<anonymous>':
undefined method `label' for Facter::Util::Partitions:Module
/var/lib/puppet/lib/facter/partitions.rb:31:in `block (3 levels) in
<top (required)>'
/var/lib/puppet/lib/facter/partitions.rb:26:in `each'
/var/lib/puppet/lib/facter/partitions.rb:26:in `block (2 levels) in
<top (required)>'
/usr/lib/ruby/vendor_ruby/facter/util/resolution.rb:157:in `call'
/usr/lib/ruby/vendor_ruby/facter/util/resolution.rb:157:in `resolve_value'
/usr/lib/ruby/vendor_ruby/facter/core/resolvable.rb:63:in `block (2
levels) in value'
/usr/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/usr/lib/ruby/vendor_ruby/facter/core/resolvable.rb:62:in `block in value'
/usr/lib/ruby/vendor_ruby/facter/core/resolvable.rb:84:in `with_timing'
/usr/lib/ruby/vendor_ruby/facter/core/resolvable.rb:61:in `value'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:161:in `block in
find_first_real_value'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:160:in `each'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:160:in `find_first_real_value'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:113:in `block in value'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:145:in `searching'
/usr/lib/ruby/vendor_ruby/facter/util/fact.rb:110:in `value'
/usr/lib/ruby/vendor_ruby/facter/util/collection.rb:130:in `value'
/usr/lib/ruby/vendor_ruby/facter.rb:117:in `value'
/usr/lib/ruby/vendor_ruby/facter/application.rb:37:in `block in run'
/usr/lib/ruby/vendor_ruby/facter/application.rb:35:in `each'
/usr/lib/ruby/vendor_ruby/facter/application.rb:35:in `run'
/usr/bin/facter:20:in `<main>'


Anyway I'm attaching the fact that is giving me this error. The error
is thrown by

# facter -p --yaml partitions --trace

Thanks!
> --
> 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 puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/54B30F5D.3070005%40Alumni.TU-Berlin.de.
> For more options, visit https://groups.google.com/d/optout.
partitions_fact_modified.tar.gz

Felix Frank

unread,
Jan 12, 2015, 9:56:00 AM1/12/15
to puppet...@googlegroups.com
On 01/12/2015 01:22 PM, Davide Ferrari wrote:
> Hello!
>
> My code is basically this commit
>
> https://github.com/vide/facter/commit/c4060af48074c372a63409d81b836b79ff5d0427
>
> This patch works smoothly if I overwrite the files in /usr/lib/ruby/vendor_ruby/

All right, awesome. Thanks for that.

I think the issue is that facter/util is not supposed to be pluggable
this way. Custom facts live in lib/facter/*.rb and that's the extent of
it. I may be mistaken, but it seems consistent to me that this will not
work.

I would hope that you can build your override in a fashion to
1. run the original resolution
2. modify the value to add the 'label' key in the way you need
...instead of copy-pasting the complete original fact code.

I'd need to go code-diving to find out how one would go about this
exactly, or whether it is at all possible. Please let us know if you
manage to build something like this on your own in the meantime :-)

Cheers,
Felix

Davide Ferrari

unread,
Jan 12, 2015, 12:24:21 PM1/12/15
to puppet...@googlegroups.com
Ok, I'll try to see if I can find a solution by myself meanwhile.
Maybe the override should be done as you say, so, in a different
fashion than the upstream patch.

Cheers
> --
> 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 puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/54B3E076.5090609%40alumni.tu-berlin.de.

Felix Frank

unread,
Jan 19, 2015, 11:15:29 AM1/19/15
to puppet...@googlegroups.com
On 01/12/2015 03:55 PM, Felix Frank wrote:
> I think the issue is that facter/util is not supposed to be pluggable
> this way. Custom facts live in lib/facter/*.rb and that's the extent of
> it. I may be mistaken, but it seems consistent to me that this will not
> work.

Hi,

I just found that this is most likely a false assumption of mine.

https://github.com/puppetlabs/puppetlabs-stdlib/tree/master/lib/facter/util

So, yeah, that should work. Although I'm still not sure what Ruby will
do if you sync a file to util/ that is also present in the system wide
facter/util/ tree. It's likely safer to give unique names to your fact
code files, except when you are overriding existing facts (not their
utility functions, mind).

Best,
Felix

Davide Ferrari

unread,
Jan 19, 2015, 11:30:39 AM1/19/15
to puppet...@googlegroups.com
Mmmh it still doesn't work for me :( As a workaround, I created
another fact which just executes the "partitions" fact and then add
the labels to the appropriate partions. My PR was accepted :) so I've
just to wait a new upstream version to remove the workaround. Anyway
if you (or anybody) find some way to properly override a complex fact,
keep me informed!

Thanks for your time
> --
> 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 puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/54BD2D92.90408%40alumni.tu-berlin.de.
Reply all
Reply to author
Forward
0 new messages