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.
MyTypeis an alias of the
type MyModule::MyType = Integer notice MyModule::MyType == Integer
TypeAliasare never values in Puppet code .
Creating type aliases
type <MODULE NAME>::<ALIAS NAME> = <TYPE DEFINITION>
<MODULE NAME>must be named after the module that contains the type alias, and both the
<ALIAS NAME>begin with a capital letter and must not be a reserved word.
MyTypethat is equivalent to the
You can then declare a parameter using the alias as though it were a unique data type:
type MyModule::MyType = Integer
MyModule::MyType $example = 10
To make your code easier to maintain and troubleshoot, store type aliases as
.pp files in your module's
which is a top-level directory and sibling of the
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
Anytype. For example:
type MyModule::Tree = Array[Variant[Data, Tree]]
Treetype alias is defined as a being built out of Arrays that contain Data, or a Tree:
[1,2 , [4, [5, 6], [[[[1,2,3]]]]]]
When defining an alias to a resource type, use its short form (for example,
type MyModule::MyFile = File
File) instead of its long form (