Issue #20408 has been updated by Andrew Parker.

Tracker changed from Bug to Feature

I can think of two ways of achieving this, one is really simple and the other 
is much more complicated.

First the simple one: Allow a fact to call itself, but ignore the current 
resolution when getting the value. For example if we were able to do:

<pre>
Facter.add(:my_fact) do
  confine :osfamily => "RedHat"
  setcode do
    { :my => "value" }
  end
end

Facter.add(:my_fact) do
  confine :osfamily => "RedHat", :architecture => "x86_64"
  setcode do
    Facter.value(:my_fact).merge({ :other => "different value" })
  end
end
</pre>

Now if that call to `Facter.value` in the second resolution would skip the 
second resolution when looking up the fact, then you could do what it is doing 
by taking the result and modifying it. This would allow a simple composition of 
facts.

A much more complicated, but declarative way would be to provide something like 
hiera's lookup system. Conceptually each fact is a value in hiera and each 
resolution is a level of the hierarchy. Since facter isn't interacted with on a 
query basis like hiera (you just ask for a value instead of also specifying how 
to compose the value), then I think each resolution would need to declare how 
to combine it with other suitable resolutions. For example:

<pre>
Facter.add(:my_fact) do
  merge :none # specify that this resolution stands by itself if it is the most 
suitable resolution
  setcode do
    ....
  end
end

Facter.add(:my_fact) do
  merge :override # specify that this resolution's values take precedence over 
any other less-suitable resolution's values.
                           # For a hash a shallow merge, and for a scalar value 
or array this takes precedence
  setcode do
    ....
  end
end

Facter.add(:my_fact) do
  merge :union # specify that this resolution's values are combined with any 
other less-suitable resolution's values.
                        # For an array this would be a union, for a hash a deep 
merge, and for a scalar value this takes precedence they are converted to an 
array of both values
  setcode do
    ....
  end
end
</pre>

----------------------------------------
Feature #20408: Should be possible to merge structured facts
https://projects.puppetlabs.com/issues/20408#change-94576

* Author: Erik Dalén
* Status: Investigating
* Priority: Normal
* Assignee: Andrew Parker
* Category: 
* Target version: 2.0.0
* Keywords: structured facts hash
* Branch: 
* Affected Facter version: 
----------------------------------------
To be able to extend one structured fact with more data it should be possible 
to deep merge two facts.

For example it there was a "interfaces" hash containing network interfaces and 
info about them and you wanted to add LLDP information to them you could add 
another interfaces fact that would get deep merged with the original one.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to