The Puppet language
You'll use Puppet's declarative language to describe the desired state of your system.
You'll describe the desired state of your system in files called manifests. Manifests describe how your network and operating system resources, such as files, packages, and services, should be configured. Puppet then compiles those manifests into catalogs, and applies each catalog to its corresponding node to ensure the node is configured correctly, across your infrastructure.
Several parts of the Puppet language depend on evaluation order. For example, variables must be set before they are referenced. Throughout the language reference, we call out areas where the order of statements matters.
If you are new to Puppet, start with the Puppet language overview.
-
Puppet language overview
The following overview covers some of the key components of the Puppet language, including catalogs, resources, classes and manifests. -
Puppet language syntax examples
A quick reference of syntax examples for the Puppet language. -
The Puppet language style guide
This style guide promotes consistent formatting in the Puppet language, giving you a common pattern, design, and style to follow when developing modules. This consistency in code and module structure makes it easier to update and maintain the code. -
Files and paths on Windows
Puppet and Windows handle directory separators and line endings in files somewhat differently, so you must be aware of the differences when you are writing manifests to manage Windows systems. -
Code comments
To add comments to your Puppet code, use shell-style or hash comments. -
Variables
Variables store values so that those values can be accessed in code later. -
Resources
Resources are the fundamental unit for modeling system configurations. Each resource describes the desired state for some aspect of a system, like a specific service or package. When Puppet applies a catalog to the target system, it manages every resource in the catalog, ensuring the actual state matches the desired state. -
Resource types
Every resource (file, user, service, package, and so on) is associated with a resource type within the Puppet language. The resource type defines the kind of configuration it manages. This section provides information about the resource types that are built into Puppet. -
Relationships and ordering
Resources are included and applied in the order they are defined in their manifest, but only if the resource has no implicit relationship with another resource, as this can affect the declared order. To manage a group of resources in a specific order, explicitly declare such relationships with relationship metaparameters, chaining arrows, and therequire
function. -
Classes
Classes are named blocks of Puppet code that are stored in modules and applied later when they are invoked by name. You can add classes to a node’s catalog by either declaring them in your manifests or assigning them from an external node classifier (ENC). Classes generally configure large or medium-sized chunks of functionality, such as all of the packages, configuration files, and services needed to run an application. -
Defined resource types
Defined resource types, sometimes called defined types or defines, are blocks of Puppet code that can be evaluated multiple times with different parameters. -
Bolt tasks
Bolt tasks are single actions that you can run on target nodes in your infrastructure, allowing you to make as-needed changes to remote systems. You can run tasks with the Puppet Enterprise (PE) orchestrator or with Puppet’s standalone task runner, Bolt. -
Expressions and operators
Expressions are statements that resolve to values. You can use expressions almost anywhere a value is required. Expressions can be compounded with other expressions, and the entire combined expression resolves to a single value. -
Conditional statements and expressions
Conditional statements let your Puppet code behave differently in different situations. They are most helpful when combined with facts or with data retrieved from an external source. Puppet supports if and unless statements, case statements, and selectors. -
Function calls
Functions are plug-ins, written in Ruby, that you can call during catalog compilation. A call to any function is an expression that resolves to a value. Most functions accept one or more values as arguments, and return a resulting value. -
Built-in function reference
-
Node definitions
A node definition, also known as a node statement, is a block of Puppet code that is included only in matching nodes' catalogs. This allows you to assign specific configurations to specific nodes. -
Facts and built-in variables
Before requesting a catalog for a managed node, or compiling one withpuppet apply
, Puppet collects system information, called facts, by using the Facter tool. The facts are assigned as values to variables that you can use anywhere in your manifests. Puppet also sets some additional special variables, called built-in variables, which behave a lot like facts. -
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. -
Custom resources
A resource is the basic unit that is managed by Puppet. Each resource has a set of attributes describing its state. Some attributes can be changed throughout the lifetime of the resource, whereas others are only reported back but cannot be changed, and some can only be set one time during initial creation. -
Custom functions
Use the Puppet language, or the Ruby API to create custom functions. -
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. -
Templates
Templates are written in a specialized templating language that generates text from data. Use templates to manage the content of your Puppet configuration files via thecontent
attribute of thefile
resource type. -
Advanced constructs
Advanced Puppet language constructs help you write simpler and more effective Puppet code by reducing complexity. -
Details of complex behaviors
Within Puppet language there are complex behavior patterns regarding classes, defined types, and specific areas of code called scopes. -
Securing sensitive data in Puppet
Puppet’s catalog contains sensitive information in clear text. Puppet uses theSensitive
data type to mark your sensitive data — for example secrets, passwords and private keys — with a flag that hides the value from certain parts of Puppet, such as reports. However, you can still see this information in plain text files in the cached catalog and other administrative functions.