Book Image

LEARNING PUPPET

Book Image

LEARNING PUPPET

Overview of this book

Table of Contents (17 chapters)
Learning Puppet
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating custom facts


So far, in this book, we have been using Puppet's built-in facts, such as the ipaddress_eth1 and uptime. In comparison to functions, facts are much easier to use as they don't accept arguments. We just reference them like we reference any Puppet variable using the $fact_name or $::fact_name syntax. Personally, I like to use the $::fact_name syntax because it clearly defines the scope of the variable. This is also the syntax recommended in the Puppet Language Style Guide (https://docs.puppetlabs.com/guides/style_guide.html). The $:: prefix in Puppet variables means that the variable scope is global ($::fact_name) as opposed to local ($fact_name). Although Puppet doesn't allow you to declare a local variable with the same name as a fact, it is a good practice to include the scope prefix ($::) when referencing facts. When someone is studying a manifest that I've written, they can easily see from the $:: prefix that the variable is referencing the fact rather than the local...