Resources in Puppet Configuration - In the last article on Puppet - "How to Install and Configure Puppet Master and Puppet Agent in Linux", we learned to create and configure Puppet master and Puppet agent node. In this article, we will be learning about the very basic component of Puppet configuration, known as Resources.
What are Resources?
As mentioned, Resources are the fundamental components of a system, which have certain Attributes - state it can be in (present or absent, enabled or disabled, etc.) or an action associated with it (create, delete or modify). With these resources, we can have control on system parameters (like files, users, packages, services, etc.).
Depending on what system parameter a resource can manipulate and configuration it controls, each resource belongs to a particular Resource Type. The complete list of the resource types is provided here. In this article, we will see some of the basic resource types used in writing a Puppet code (also known as Manifest).
This resource type is used to manage files, directories and symbolic links (Read more about symbolic links). As I mentioned, every resource has a set of attributes associated with it. So lets check out come important attributes associated with a
path- It states the absolute path of the file/directory.
- Example -
ensure- It states the existence of a file on the system i.e. it is
absent. If it is present, whether it is a
link. If it is a link, one should also mention about the
targetattribute, representing the source file it must point to.
content- This attribute represent what text the file will contain. In this case, you can mention the content within single quotes, like
'Hello world!'or you can use the
sourceattribute, which expects a path to a file. So that, both these files will have same contents.
mode- This attributes represents the permissions on the file in octal notations, like
group- These attributes are associated with ownership of the file.
replace- Valid values for this attributes are
no. It states whether the file should be replaced if already present or otherwise.
source- As mentioned above, this attribute expects a path to a file, on the same system or the Puppet master. Thus, this file will have the same contents as that of the source file mentioned.
This resource type is used to manage packages on the Puppet agent nodes, including installation, updation and removal. Lets see some of the attributes associated with this resource type.
name- Name of the package.
- Example -
ensure- It states the existence of a package on the system i.e. it should be
provider- This attribute represent what backend/package manager, like
zypper, it should use to install/remove the package.
source- This attribute is used to represent where to find a package, in case a package is not provided by the provider and available in a remote central repository.
This resource type is used to manage services on the Puppet agent nodes. It includes starting, stopping and restarting the service. Not only this, to add or remove the service from startup. Lets see some of the attributes associated with this resource type.
name- Name of the service.
ensure- It denotes the state of a service on the system i.e. it should be
enable- This attribute represents whether a service should start at system boot or not. So, the valid values are
path- With this attribute, we can specify the path where Puppet can find the init scripts.
This resource type is used to manage system users on the Puppet agent nodes. It includes addition, deletion and modification of the users. Lets see some of the attributes associated with this resource type.
name- Name of the user.
ensure- It denotes the state of a user on the system i.e. it should be
comment- This attribute represents description of the user, like
'Nagios Admin User'.
expiry- With this attribute, we can specify the date, in YYYY-MM-DD format, when the user account expires.
gid- UID and GID of the user.
shell- Shell of the user, like
This resource type is used to execute system commands on the Puppet agent nodes, provided that, the command should be Idempotent (meaning that, it should always produce same result when executed multiple times). Lets see some of the attributes associated with this resource type.
command- Command name.
cwd- Name of the directory from which command should be executed. If directory does not exist, command execution will fail.
creates- File that should be looked for before executing the command. If file doesn't exist, command will be executed and file will be created.
onlyif- With this attribute, we can set dependency of the executing based on exit status of another command. So, if the other command executes successfully, this command will be executed, otherwise not.
path- The path that should be searched to find the command.
returns- Exit status of the command which should be returned, must be an integer between 0-255.
timeout- The maximum time the command should take for completing the execution.
unless- Opposite of
onlyif. The command will be executed if exit status of other command is non-zero.
That's it for this article, which was supposed to introduce you with Puppet Resources. In the next article, we will learn about another new concept - Puppet Manifests. Till then, stay tuned!