Open source Puppet documentation

You can use only certain characters for naming variables, modules, classes, defined types, and other custom constructs. Additionally, some words in the Puppet language are reserved and cannot be used as bare word strings or names.

Reserved words

Reserved words cannot be used as:
  • Bare word strings—to use these words as strings, you must enclose them in quotes.
  • Names for custom functions.
  • Names for classes.
  • Names for custom resource types or defined resource types.
In addition, do not:
  • Use the name of any existing resource type or function as the name of a function.
  • Use the name of any existing resource type as the name of a defined type.
  • Use the name of any existing data type (such as integer) as the name of a defined type.
Table 1.
Reserved wordDescription
andExpression operator
applicationLanguage keyword
attrReserved for future use
caseLanguage keyword
component Reserved
consumesLanguage keyword
defaultLanguage keyword
defineLanguage keyword
elsifLanguage keyword
environmentReserved for symbolic namespace use
falseBoolean value
functionLanguage keyword
ifLanguage keyword
importFormer language keyword
inExpression operator
inheritsLanguage keyword
nodeLanguage keyword
orExpression operator
privateReserved for future use
producesLanguage keyword
regexp Reserved
siteLanguage keyword
trueBoolean value
typeLanguage keyword
undefSpecial value
unit Reserved
unlessLanguage keyword

Reserved class names

Puppet automatically creates two names that must not be used as class names elsewhere:
  • main: Puppet creates a main class, which contains any resources not contained by any other class.
  • settings: Puppet creates a settings namespace, which contains variables with the settings available to the master.
Additionally, the names of data types can't be used as class names:
  • any, Any
  • array, Array
  • boolean, Boolean
  • catalogentry, catalogEntry, CatalogEntry
  • class, Class
  • collection, Collection
  • callable, Callable
  • data, Data
  • default, Default
  • enum, Enum
  • float, Float
  • hash, Hash
  • integer, Integer
  • numeric, Numeric
  • optional, Optional
  • pattern, Pattern
  • resource, Resource
  • runtime, Runtime
  • scalar, Scalar
  • string, String
  • struct, Struct
  • tuple, Tuple
  • type, Type
  • undef, Undef
  • variant, Variant

Reserved variable names

The following variable names are reserved. Unless otherwise noted, you can't assign values to them or use them as parameters in classes or defined types.
Table 2.
Reserved variable nameDescription
$0, $1, and every other variable name consisting only of digitsThese are regex capture variables automatically set by regular expression used in conditional statements. Their values do not persist oustide their associated code block or selector value. Assigning these variables causes an error.
Top-scope Puppet built-in variables and facts Built-in variables and facts are reserved at top scope, but you can safely reuse them at node or local scope. See built-in variables and facts for a list of these variables and facts.
$factsReserved for facts and cannot be reassigned at local scopes.
$trustedReserved for facts and cannot be reassigned at local scopes.
$server_factsIf enabled, this variable is reserved for trusted server facts and cannot be reassigned at local scopes.
titleReserved for the title of a class or defined type.
nameReserved for the name of a class or defined type.

Acceptable characters in names

Puppet limits the characters you can use when naming language constructs.

CAUTION: In some cases, names containing unsupported characters might still work. Such cases are bugs and could cease to work at any time. Removal of these bug cases is not limited to major releases.

Classes and defined resource type names

The names of classes and defined resource types can consist of one or more namespace segments. Each namespace segment:
  • Must begin with a lowercase letter.
  • Can include lowercase letters.
  • Can include digits.
  • Can include underscores.
When you follow these rules, each namespace segment matches the following regular expression:
\A[a-z][a-z0-9_]*\Z
The one exception is the top namespace, whose name is the empty string.
Multiple namespace segments are joined together in a class or defined type name with the double colon namespace separator: ::. Class names with multiple namespaces should match the following regular expression:
\A([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*\Z
Some words and class names are reserved and cannot be used as class or defined type names. Additionally, the filename init.pp is reserved for the class named after any given module, so you cannot use the name <MODULE NAME>::init for a class or defined type.

Variable names

Variable names are case-sensitive and must begin with a dollar sign ($). Most variable names must start with a lowercase letter or an underscore. The exception is regex capture variables, which are named with only numbers.

Variable names can include:
  • Uppercase and lowercase letters

  • Numbers

  • Underscores ( _ ). If the first character is an underscore, access that variable only from its own local scope.

Qualified variable names are prefixed with the name of their scope and the double colon (::) namespace separator. For example, the $vhostdir variable from the apache::params class would be $apache::params::vhostdir.

Optionally, the name of the very first namespace can be empty, representing the top namespace. The main reason to namespace this way is to indicate to anyone reading your code that you're accessing a top-scope variable, such as $::is_virtual.

You can also use a regular expression for variable names. Short variable names match the following regular expression:
\A\$[a-z0-9_][a-zA-Z0-9_]*\Z
Qualified variable names match the following regular expression:
\A\$([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*::[a-z0-9_][a-zA-Z0-9_]*\Z

Module names

Module names obey the same rules as individual namespace segments, just as in a class or defined type name. That is, each namespace segment:
  • Must begin with a lowercase letter.
  • Can include lowercase letters.
  • Can include digits.
  • Can include underscores.
When you follow these rules, each namespace segment matches the following regular expression:
\A[a-z][a-z0-9_]*\Z

Reserved words and class names cannot be used as module names.

Parameter names

Parameter names begin with a dollar sign prefix ($). The parameter name after the prefix:
  • Must begin with a lowercase letter.
  • Can include lowercase letters.
  • Can include digits.
  • Can include underscores.
When you follow these rules, a parameter name matches the following regular expression:
\A\$[a-z][a-z0-9_]*\Z

Tag names

Tag names must begin with:
  • A lowercase letter, or

  • An number, or

  • An underscore.

Tag names can include:
  • Lowercase letters

  • Uppercase letters

  • Digits

  • Underscores

  • Colons

  • Periods

  • Hyphens

When you follow these rules, a tag name matches the following regular expression:
\A[[:alnum:]_][[:alnum:]_:.-]*\Z

Resource names

Resource titles can contain any characters whatsoever and are case-sensitive. Resource names, or the namevar attribute, might be limited by the system being managed. For example, most operating systems have limits on the characters permitted in the name of a user account. You are generally responsible for knowing the name limits on the platforms you manage.

Node names

Node names can contain:
  • Letters
  • Digits
  • Periods
  • Underscores
  • Dashes
That is, node names match the regular expression:
 /\A[a-z0-9._-]+\Z/

Environment names

Environment names can contain:
  • Lowercase letters
  • Numbers
  • Underscores
That is, environment names match the regular expression:
\A[a-z0-9_]+\Z 
Back to top
The page rank or the 1 our of 5 rating a user has given the page.
The email address of the user submitting feedback.
The URL of the page being ranked/rated.