Learning Kit

Puppet Language Basics


Time: 5 minutes
Materials needed: none

Resources are the core of the Puppet language. A resource is a characteristic of a node that needs to be managed over time, such as a user, a package, or a registry key. Resources allow you to express system configuration in code to automate it and apply it consistently to one or more nodes.

Since the Puppet language is declarative, a resource describes the final configuration of a node, not the steps required to achieve that state. A resource declaration adds the resource to the catalog and tells the Puppet master to manage that resource’s state.

A resource declaration begins with the resource type, which is what you want to manage. The type is followed by { (an opening curly brace), and the resource’s title in '' (single quotes). The title is a string that identifies a Puppet resource, and is typically the name of what you are managing on the target system.

After a : (colon), you’ll write each resource’s attributes. Attributes describe the desired state of the resource and each attribute handles some aspect of the resource. Each attribute follows the same formatting: the attribute, => (hash rocket), followed by the attribute’s value, and a , (comma). The resource declaration then ends with a } (closing curly brace).

Here’s an example of a resource that creates a new user named Jackie. To create a user, set the ensure attribute to present. The present value tells Puppet to check if this user resource exists on your system. If the resource doesn’t exist, Puppet will create it, bringing your infrastructure to the desired state.

This example file resource contains multiple attribute/value pairs. When a resource has multiple attributes, they should be written on their own lines for maximum readability. While the final attribute in a resource declaration technically doesn’t need a , (comma) to function, it’s recommended to use one to make it easier to rearrange or add more attributes later on.

There are many types of resources, and the ones you’ll use most often are already native to the Puppet language, including file, package, service, and user. You can also discover or write additional custom resources to fit your infrastructure’s needs.

Each resource type has its own set of attributes available to use, some crucial and some optional. Check out the Resource Type Reference in the Puppet documentation for a complete list of resources and their attributes.

Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.