How do I access the name of the puppet node (i.e., $trusted['certname']
in a manifest) within the context of a custom fact (i.e., lib/facter/my_custom_fact.rb
).
I read this question/answer, and that filled me with hope, but alas, I see no reference to the node name in the list of available facts accessible via Facter.value(:sym)
.
Thank you.
I guess I'm explaining a lot you already know but I'll start at the beginning for context.
facter -p my_custom_fact
.So you can see that the fact you want just isn't available to you at the time you're asking for it, you're asking for it at stage 2 but it's not decrypted from the node's certificate until stage 3.
Once on the Puppet server though it becomes available as a node scope variable $::trusted['certname'], from here you could pass it into a manifest or a custom function, anything that runs during stage 4.
I think the only way you'll be able to get the value into my_custom_fact.pp is to use one of the available facts from the target node when the facts are being run during step 2 and you should be able to do it by just adding the following line to my_custom_fact.pp;
my_fqdn = Facter.value('fqdn')
This is from https://puppet.com/docs/puppet/6/custom_facts.html#using_other_facts
The networking.fqdn fact is a regular facter fact, you can check that any time on a system running facter networking.fqdn
or its alias facter fqdn
.