System resources are the key elements of a Puppet code that defines the architecture and manages the configuration of a system infrastructure.
Puppet has its own DML (Declarative Modelling Language) to write code.
The main unit of code is called a resource.
Puppet uses various types of resources to define the different definitions and parameters of a system.
Here is how a resource is written:
resource_type { ‘resource_name’:
attribute => value,
attribute => value,
…
}
Each resource has 3 items: Resource_type, resource_name and the attributes.
Example:
user { ‘Jack’:
ensure => present,
owner => ‘root',
group => ‘home’,
mode => 0644,
shell => ‘/bin/bash’
}
This code evaluates as:
Resource type ‘user’ with the resource parameter ‘Jack’ have the attributes: ‘ensure’, ‘owner’, ‘group’, ‘mode’ and ‘shell’.
These attributes have the respective values.
We can get a list of all the available resource types with the command:
puppet describe --list
Some of the common resource types are:
-
user
-
package
-
exec
-
file
-
service
Example of resource_type: ‘service’. This resource ensures that the service: ‘network’ is running
service
{‘network’ :
ensure => running
}
This resource checks the ‘package’: ‘apache’ is running and its pre-requisite requires ‘apt-update’ command to be executed.
package { ‘apache’ :
require => Exec[‘apt-update’],
ensure => running
}