Values, data types, and aliases
Most of the things you can do with the Puppet language involve some form of data. An individual piece of data is called a value, and every value has a data type, which determines what kind of information that value can contain and how you can interact with it.
Strings are the most common and useful data type, but you’ll also work with others, including numbers, arrays, and some Puppet-specific data types like resource references.
Note that once created, Puppet's values are immutable — they cannot be modified in any way.
For information on type conversion, see Typecasting.
Literal data types as values
Although you’ll mostly interact with values of the various data
types, Puppet also includes values like String
that represent data
types.
You can use these special values to examine a piece of data or enforce rules. Usually, they act like patterns, similar to a regular expression: given a value and a data type, you can test whether the value matches the data type, and then either adjust your code’s behavior accordingly, or raise an error if something has gone wrong.
The pages in this section provide details about using each of the data types as a value. For information about the syntax and behavior of literal data types, see Data type syntax. For information about special abstract data types, which you can use to do more sophisticated or permissive type checking, see Abstract data types.
Puppet's data types
See the following pages to learn more about the syntax, parameters, and usage for each of the data types.
-
Abstract data types
If you’re using data types to match or restrict values and need more flexibility than what the core data types (such asString
orArray
) allow, you can use one of the abstract data types to construct a data type that suits your needs and matches the values you want. -
Arrays
Arrays are ordered lists of values. Resource attributes which accept multiple values (including the relationship metaparameters) generally expect those values in an array. Many functions also take arrays, including the iteration functions. -
Binary
ABinary
object represents a sequence of bytes and it can be created from a String in Base64 format, a verbatimString
, or anArray
containing byte values. ABinary
can also be created from a Hash containing the value to convert to aBinary
. -
Booleans
Booleans are one-bit values, representing true or false. The condition of anif
statement expects an expression that resolves to a Boolean value. All of Puppet's comparison operators resolve to Boolean values, as do many functions. -
Data type syntax
Each value in the Puppet language has a data type, like “string.” There is also a set of values whose data type is “data type.” These values represent the other data types. For example, the valueString
represents the data type of strings. The value that represents the data type of these values isType
. -
Default
Puppet’sdefault
value acts like a keyword in a few specific usages. Less commonly, it can also be used as a value. -
Error data type
AnError
object contains a non-empty message. It can also contain additional context about why the error occurred. -
Hashes
Hashes map keys to values, maintaining the order of the entries according to insertion order. -
Numbers
Numbers in the Puppet language are normal integers and floating point numbers. -
Regular expressions
A regular expression (sometimes shortened to “regex” or “regexp”) is a pattern that can match some set of strings, and optionally capture parts of those strings for further use. -
Resource and class references
Resource references identify a specific Puppet resource by its type and title. Several attributes, such as the relationship metaparameters, require resource references. -
Resource types
Resource types are a special family of data types that behave differently from other data types. They are subtypes of the fairly abstractResource
data type. Resource references are a useful subset of this data type family. -
Sensitive
Sensitive types in the Puppet language are strings marked as sensitive. The value is displayed in plain text in the catalog and manifest, but is redacted from logs and reports. Because the value is maintained as plain text, use it only as an aid to ensure that sensitive values are not inadvertently disclosed. -
Strings
Strings are unstructured text fragments of any length. They’re a common and useful data type. -
Time-related data types
ATimespan
defines the length of a duration of time, and aTimestamp
defines a point in time. For example, “two hours” is a duration that can be represented as aTimespan
, while “three o'clock in the afternoon UTC on 8 November, 2018” is a point in time that can be represented as aTimestamp
. Both types can use nanosecond values if it is available on the platform. -
Undef
Puppet'sundef
value is roughly equivalent tonil
in Ruby. It represents the absence of a value. If thestrict_variables
setting isn’t enabled, variables which have never been declared have a value ofundef
.