Type aliases
Type aliases allow you to create reusable and descriptive data types and resource types.
Give a type a descriptive name, such as
IPv6Addr
, instead of creating or using a complex pattern-based type.Shorten and move complex type expressions.
Improve code quality by reusing existing types instead of inventing new types.
Test type definitions separately from manifests.
notice
returns true
because MyType
is an alias of the Integer
type:type MyModule::MyType = Integer
notice MyModule::MyType == Integer
TypeReference
and TypeAlias
are never values in Puppet code .Creating type aliases
type <MODULE NAME>::<ALIAS NAME> = <TYPE DEFINITION>
The <MODULE NAME>
must be named after the module that
contains the type alias, and both the <MODULE NAME>
and
<ALIAS NAME>
begin with a capital letter and must not be
a reserved word. MyType
that is
equivalent to the Integer
data
type:type MyModule::MyType = Integer
You can then declare a
parameter using the alias as though it were a unique data
type:MyModule::MyType $example = 10
To make your code easier to maintain and troubleshoot, store type aliases as
.pp
files in your module's types
directory,
which is a top-level directory and sibling of the manifests
and
lib
directories. Define only one alias per file, and name the
file after the type alias name converted to lowercase. For example,
MyType
is expected to be loaded from a file named
mytype.pp
.
Any
type. For
example:type MyModule::Tree = Array[Variant[Data, Tree]]
This
Tree
type alias is defined as a being built out of Arrays that
contain Data, or a Tree:[1,2 [3], [4, [5, 6], [[[[1,2,3]]]]]]
type MyModule::MyFile = File
When defining an alias to
a resource type, use its short form (for example, File
) instead of
its long form (Resource[File]
).