In puppet, all the programs are written in Ruby programming language and added with an extension of .pp is known as manifests. The full form of .pp is the puppet program.
Manifest files are puppet programs. This is used to manage the target host system. All the puppet programs follow the puppet coding style.
We can use a set of different kinds of resources in any manifest, which is grouped by definition and class.
Puppet manifest also supports the conditional statement. The default manifest file is available in the /etc/puppet/manifests/site.pp location.
Puppet manifest has the following components:
Working with Variables
Puppet provides many in-built variables that we can use in the manifest. As well as we can create our own variable to define in puppet manifest. Puppet provides different types of variables. Some frequently used variables are strings or an array of string.
Let's see an example for string variable:
Working with Loops
Loops are used to run the same set of code multiple times until a defined condition becomes true. To perform the loop, we can use an array. Let's see an example:
Puppet allows us to use different types of conditional statements. Such as if-else statement, case statements, etc. Let's see an example:
Writing a Manifest
As we know, we can create our resources. Let's start with common resources like notify resources.
In the above code, the notify is the resource, and the message is the attribute. The message has attributes that are separated from their values by a comma, which is a very general way of identifying key-value pairs in Ruby, PHP, Perl, and other scripting languages.
Create a manifest and write the above script in that manifest. For this first, you have to switch to the root user.
Here, we can see manifests are text files named with .pp extension. We can use any editor to create or modify manifest using any text editor.
Applying a Manifest
The main quality of the puppet is the ease of testing your code. In this, to work on puppet manifests, there is no need to configure complicated testing environments.
To apply the manifest, puppet uses apply command, which tells puppet to apply a single puppet manifest:
Here, you can see, Puppet has successfully applied the manifest. This process done by many steps: