dumb question ... fact names all share a global na...
# puppet
j
dumb question ... fact names all share a global namespace. what happens if multiple modules contain the same fact (i.e.
pdk new fact xyz
) ? ... common sense tells me that only one of them would end up in
/opt/puppetlabs/puppet/cache/lib/facter/
on the target machine (even if both are sent, one would overwrite the other), so only one would end up being executed ... i know the "correct" answer is "don't do that", but if somebody does, is there any way to know which one would end up existing on the target machine?
also, if somebody creates an
/etc/facter/facts.d/
file containing a fact with a name that duplicates a custom fact sent as code, which of those would end up in the list that the compiler receives?
FWIW it never occurred to me to actually try any of this, but the target audience for the documentation i'm writing includes a few junior people with very little programming background, so namespace collisions aren't even a thing that would occur to them
b
They will overwrite themselves and the behavior is unpredictable
a
j
okay, so there are no deterministic rules, like "custom facts defined modules whose names are lexically later are sent to the agent", or "facts defined via files are overwritten by facts defined via code"? ... again, i know the correct answer is "don't do that", i'm just curious if there is a way to predict what would happen
@Adrian Parreiras Horta i had never seen "weights", thanks for pointing that out ... it looks interesting, but off the top of my head i can't think of where we would find it useful ... and i don't want to confuse my readers ... i'm just going to say "don't do that", and if somebody has questions they can come to me and ask.
n
I remember once figuring out the resolution order when there were custom facts, external facts, ruby-based facts in modules, etc... I even remember there being a slide in the courses I used to teach. But I cannot remember what that order was 🙂
Also, I would assume that order was not by design so should not be relied on.
c
remember not to call facter from inside a fact unless you hand it the --no-external-facts switch. YOu will fork-bomb your machine.
c
Weighting is the way to make it deterministic.
j
okay, that all makes sense. again, it's not something i really need, i was mostly just curious. thanks all for taking the time to answer.
c
The intentional use case here is as an escape hatch: if a fact is incorrect, it can be overridden with a higher-weight alternative while a pull request to update the module is pending.
j
makes sense
c
I found it funny when I found the facter fork bug back in ’15 that no one would’ve done that. We had a fact that parsed out a network portion of an IP then would auto-set the DNS entries based on that IP, so the second fact for DNS entries would barf because to get the network portion they needed so I could append the last octet, I had to call the first one from inside the second one. My plan at the time was to tell everyone they had to use facter as sort of like an API to the system, and people didn’t need to be spending all sorts of time writing parsing logic out, just use Facter because it was already there. That bug made me completely scrap the idea. THEN the fix for the bug wasn’t to allow you to call another fact from inside a fact, oh no… it was to not call an external fact OR give it a flag that told it not to do so. Crazy-sauce