Reserved words and acceptable names
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
- 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.
- 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.
Reserved word | Description |
---|---|
and |
Expression operator |
application |
Language keyword |
attr |
Reserved for future use |
case |
Language keyword |
component |
Reserved |
consumes |
Language keyword |
default |
Language keyword |
define |
Language keyword |
elsif |
Language keyword |
environment |
Reserved for symbolic namespace use |
false |
Boolean value |
function |
Language keyword |
if |
Language keyword |
import |
Former language keyword |
in |
Expression operator |
inherits |
Language keyword |
node |
Language keyword |
or |
Expression operator |
private |
Reserved for future use |
produces |
Language keyword |
regexp |
Reserved |
site |
Language keyword |
true |
Boolean value |
type |
Language keyword |
undef |
Special value |
unit |
Reserved |
unless |
Language keyword |
Reserved class names
-
main
: Puppet creates amain
class, which contains any resources not contained by any other class. -
settings
: Puppet creates asettings
namespace, which contains variables with the settings available to the primary server.
-
any
,Any
-
array
,Array
-
binary
,Binary
-
boolean
,Boolean
-
catalogentry
,catalogEntry
,CatalogEntry
-
class
,Class
-
collection
,Collection
-
callable
,Callable
-
data
,Data
-
default
,Default
-
deferred
,Deferred
-
enum
,Enum
-
float
,Float
-
hash
,Hash
-
integer
,Integer
-
notundef
,NotUndef
-
numeric
,Numeric
-
optional
,Optional
-
pattern
,Pattern
-
resource
,Resource
-
regexp
,Regexp
-
runtime
,Runtime
-
scalar
,Scalar
-
semver
,SemVer
-
semVerRange
,SemVerRange
-
sensitive
,Sensitive
-
string
,String
-
struct
,Struct
-
timespan
,Timespan
-
timestamp
,TImestamp
-
tuple
,Tuple
-
type
,Type
-
undef
,Undef
-
variant
,Variant
Reserved variable names
Reserved variable name | Description |
---|---|
$0 , $1 , and every other
variable name consisting only of digits |
These 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. |
$facts |
Reserved for facts and cannot be reassigned at local scopes. |
$trusted |
Reserved for facts and cannot be reassigned at local scopes. |
$server_facts |
If enabled, this variable is reserved for trusted server facts and cannot be reassigned at local scopes. |
title |
Reserved for the title of a class or defined type. |
name |
Reserved for the name of a class or defined type. |
Acceptable characters in names
Puppet limits the characters you can use when naming language constructs.
Classes and defined resource type names
- Must begin with a lowercase letter.
- Can include lowercase letters.
- Can include digits.
- Can include underscores.
\A[a-z][a-z0-9_]*\Z
The one exception
is the top namespace, whose name is the empty string.::
. Class names with multiple
namespaces must 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.
-
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
.
\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
- Must begin with a lowercase letter.
- Can include lowercase letters.
- Can include digits.
- Can include underscores.
\A[a-z][a-z0-9_]*\Z
Reserved words and class names cannot be used as module names.
Parameter names
$
). The parameter name after the
prefix:- Must begin with a lowercase letter.
- Can include lowercase letters.
- Can include digits.
- Can include underscores.
\A\$[a-z][a-z0-9_]*\Z
Tag names
-
A lowercase letter, or
-
An number, or
-
An underscore.
-
Lowercase letters
-
Uppercase letters
-
Digits
-
Underscores
-
Colons
-
Periods
-
Hyphens
\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
- Letters
- Digits
- Periods
- Underscores
- Dashes
/\A[a-z0-9._-]+\Z/
Environment names
- Lowercase letters
- Numbers
- Underscores
\A[a-z0-9_]+\Z