Variables

Sections

Reference variables in a clear, unambiguous way that is consistent with the Puppet style.

Referencing facts

When referencing facts, prefer the $facts hash to plain top-scope variables (such as $::operatingsystem).

Although plain top-scope variables are easier to write, the $facts hash is clearer, easier to read, and distinguishes facts from other top-scope variables.

Namespacing variables

When referencing top-scope variables other than facts, explicitly specify absolute namespaces for clarity and improved readability. This includes top-scope variables set by the node classifier and in the main manifest.

This is not necessary for:
  • the $facts hash.

  • the $trusted hash.

  • the $server_facts hash.

These special variable names are protected; because you cannot create local variables with these names, they always refer to top-scope variables.

Good:
$facts['operatingsystem']
Bad:
$::operatingsystem
Very bad:
$operatingsystem

Variable format

When defining variables you must only use numbers, lowercase letters, and underscores. Do not use uppercased letters within a word, such as “CamelCase”, as it introduces inconsistency in style. You must not use dashes, as they are not syntactically valid.

Good:
$foo_bar
$some_long_variable
$foo_bar123
Bad:
$fooBar
$someLongVariable
$foo-bar123
How helpful was this page?
Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.