Accessing facts from Puppet code
When you write Puppet code, you can access facts with
the $facts['fact_name']
hash.
Using the $facts['fact_name']
hash syntax
Alternatively, facts are structured in a $facts
hash, and your
manifest code can access them as $facts['fact_name']
. The variable
name $facts
is reserved, so local scopes cannot re-use it.
Structured facts show up as a nested structure inside the $facts
namespace, and can be accessed using Puppet's normal
hash access syntax.
if $facts['os']['family'] == 'RedHat' {
# ...
}
Accessing facts using this syntax makes for more readable and maintainable code, by making facts visibly distinct from other variables. It eliminates confusion that is possible when you use a local variable whose name happens to match that of a common fact.
Because of ambiguity with function invocation, the dot-separated access syntax that is available
in Facter commands is not available with the
$facts
hash access syntax. However, you can instead use the
get
function built into core Puppet. For more information, see README.
Improving performance by blocking or caching built-in facts
facter.conf
file:-
blocklist
for blocking built-in facts you’re uninterested in. -
ttls
for caching built-in facts you don’t need retrieved frequently.