Puppet Language Basics: Resources, Types, Attributes, Titles and Resource Declarations

Puppet Training Course 20 min min read Updated: Nov 17, 2026 Beginner
Puppet Language Basics: Resources, Types, Attributes, Titles and Resource Declarations
Beginner Topic 3 of 3

Resource Syntax

puppet type { 'title': attribute1 => value1, attribute2 => value2, }
PartMeaning
typeKind of thing: package, file, service, user... (lowercase)
titleA unique name for this resource in the catalog (string in quotes)
attributesProperties describing desired state, in name => value form
commaSeparates attributes. A trailing comma after the last one is allowed and recommended
puppet package { 'git': ensure => installed, } file { '/etc/motd': ensure => file, owner => 'root', group => 'root', mode => '0644', content => "Welcome. This server is managed by Puppet.\n", }

Title and Namevar

Each resource type has one attribute that identifies the real thing, called the namevar. If you do not set it, Puppet uses the title. For file the namevar is path, for package and service it is name, for user it is name.

puppet # These two are the same resource package { 'httpd': ensure => installed, } package { 'web-server-package': name => 'httpd', # name is the namevar, title is just a label ensure => installed, }
Why use a different title? Titles must be unique across the whole catalog. A different title plus name => lets two modules refer to the same resource name without a clash, and lets you write a stable title like Package['webserver'] while the real package name changes per OS.

The ensure Attribute

TypeCommon ensure values
packageinstalled (or present), absent, latest, or a version like '1.2.3'
filefile, directory, link, absent
servicerunning, stopped
user, grouppresent, absent
puppet package { 'telnet': ensure => absent } package { 'nginx': ensure => '1.24.0-1ubuntu1' } file { '/tmp/old': ensure => absent } file { '/opt/data': ensure => directory } file { '/etc/localtime': ensure => link, target => '/usr/share/zoneinfo/UTC' }
latest in production: ensure => latest upgrades the package on every run whenever a new version appears, which may surprise you. Prefer installed, or an exact version, and update on purpose.

Quoting and Values

KindExampleNotes
Single-quoted string'hello ${name}'No variable interpolation. Use for plain text
Double-quoted string"hello ${name}"Interpolates ${variable}. Supports \n
Barewordinstalled, present, trueLowercase words are allowed as values
Number8080, 0.5Real numbers
Booleantrue, falseNo quotes
UndefundefMeans no value
Array['a', 'b', 'c']Ordered list
Hash{ key => 'value' }Key-value pairs
File modes are strings: Write mode => '0644' in quotes. An unquoted number may be read as a different value.

Multiple Resources in One Declaration

puppet # Array of titles: same attributes for each package { ['git', 'curl', 'vim', 'tree']: ensure => installed, } # Several resources of one type in one block, separated by semicolons user { 'alice': ensure => present, shell => '/bin/bash'; 'bob': ensure => present, shell => '/bin/zsh'; }

Resource Defaults

puppet File { owner => 'root', group => 'root', mode => '0644', } file { '/etc/app.conf': ensure => file, content => "a=1\n" } # inherits the defaults file { '/etc/secret': ensure => file, content => "x\n", mode => '0600' } # overrides mode

Defaults apply to all resources of that type in the same scope (and nested scopes). Use them sparingly inside classes, so they do not surprise other code.

Resource References

To point to another resource, write the type with a capital first letter and the title in square brackets.

puppet file { '/etc/nginx/nginx.conf': ensure => file, require => Package['nginx'], # Package['nginx'] refers to package { 'nginx': } notify => Service['nginx'], }

Comments

puppet # single-line comment /* multi-line comment */

Duplicate Declarations

A resource title (and namevar) may be declared only once per catalog for each type. If two places declare the same resource Puppet stops with:

text Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Package[nginx] is already declared at (file: /etc/.../a.pp, line: 3); cannot redeclare (file: .../b.pp, line: 7)

Fix it by declaring the resource in one place only (usually inside one class) and having other code depend on that class. Later you will learn ensure_resource, virtual resources and include to avoid duplicates.

The Resource Abstraction Layer and Providers

The same resource type works on different operating systems because each type has providers, the code that knows how to do the job on one platform. For package the providers include apt, yum, dnf, zypper, gem, pip, chocolatey. Puppet chooses the right provider automatically, or you can set it with provider =>.

puppet package { 'requests': ensure => installed, provider => 'pip3', # install a Python package instead of an OS package } package { 'bundler': ensure => installed, provider => 'gem', }
bash puppet describe package --providers puppet resource package --types

Metaparameters

Some attributes work on every resource type. They are called metaparameters.

MetaparameterPurpose
require, beforeOrdering
notify, subscribeOrdering plus refresh (restart)
tagLabel resources for filtering
noopPer-resource dry run
schedule, audit, loglevelAdvanced control
puppet file { '/etc/important.conf': ensure => file, noop => true, # report what would change but do not change it }

Practice Tasks

  1. Write a manifest that installs three packages with one array declaration
  2. Create a directory, a file inside it and a symbolic link to the file
  3. Use a resource default so every file has owner root and mode 0644, with one override
  4. Cause a duplicate declaration error on purpose and read the message
  5. Use puppet describe file to find five attributes you have not used yet

Conclusion

Every Puppet resource has a type, a unique title and attributes. The namevar identifies the real object, providers adapt the type to each OS, and metaparameters such as require work on all resources.

Quick Summary: type { 'title': attr => value }; namevar; ensure; capitalised references; resource defaults; no duplicate declarations; providers.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators