Use other facts in common fact

I am having a difficult time with the following custom; below.

The custom fact should look for a specific file json

in the following folder. This displays information when used in a manifest. But, when I add it to such a fact, it doesn't work.

"/opt/${::hostname}/${::custom_variable}_${::fqdn}.json"

      

However, if I hard-code the values ​​as shown below, it works fine.

"/opt/host1.domain.com/mycompany_host1.json"

      

Note that the custom variable is defined in the Puppet console against "classification".

+3


source to share


1 answer


If you need to use facts within a custom fact, you need to access them using the Facter .value

. Their values ​​are available when facts are referenced as symbolic arguments to this method (for example Facter.value(:hostname)

). To be able to use the Facter class, you must require it in your Ruby file for a custom fact with:

require 'facter'

      

Then you can use the variables in the above example in the usual way with string interpolation:



"/opt/#{Facter.value(:hostname)}/#{Facter.value(:custom_variable)}_#{Facter.value(:fqdn)}.json"

      

Note that the fact custom_variable

needs to be assigned in the system during pluginsync before being used in this normal fact. Also, you switched the hostname and fqdn in your example above, so make sure they align correctly for you when you implement this.

https://docs.puppet.com/facter/3.6/custom_facts.html#using-other-facts

+4


source







All Articles