Puppet - Manifest Files

In Puppet, all the programs which are written using Ruby programming language and saved with an extension of .pp are called manifests. In general terms, all Puppet programs which are built with an intension of creating or managing any target host machine is called a manifest. All the programs written in Puppet follow Puppet coding style.
The core of Puppet is the way resources are declared and how these resources are representing their state. In any manifest, the user can have a collection of different kind of resources which are grouped together using class and definition.
In some cases, Puppet manifest can even have a conditional statement in order to achieve a desired state. However, ultimately it all comes down to make sure that all the resources are defined and used in the right way and the defined manifest when applied after getting converted to a catalog is capable of performing the task for which it was designed.
Puppet manifest consists of the following components −
Files (these are plain files where Puppet has nothing to do with them, just to pick them up and place them in the target location)
Files (these are plain files where Puppet has nothing to do with them, just to pick them up and place them in the target location)
Resources
Resources
Templates (these can be used to construct configuration files on the node).
Templates (these can be used to construct configuration files on the node).
Nodes (all the definition related to a client node is defined here)
Nodes (all the definition related to a client node is defined here)
Classes
Classes
In Puppet, all manifest files use Ruby as their encoding language and get saved with .pp extension.
In Puppet, all manifest files use Ruby as their encoding language and get saved with .pp extension.
"Import" statement in many manifest are used for loading files when Puppet starts.
"Import" statement in many manifest are used for loading files when Puppet starts.
In order to import all files contained in a directory, you can use the import statement in another way like import 'clients/*'. This will import all .pp files inside that directory.
In order to import all files contained in a directory, you can use the import statement in another way like import 'clients/*'. This will import all .pp files inside that directory.
While writing a manifest, the user can define a new variable or use an existing variable at any point in a manifest. Puppet supports different kind of variables but few of them are frequently used such as strings and array of string. Apart from them, other formats are also supported.
$package = "vim"  

package {  $package: 
   ensure => "installed" 
}
Loops are used when one wishes to go through multiple iterations on a same set of code till a defined condition is met. They are also used to do repetitive tasks with different set of values. Creating 10 tasks for 10 different things. One can create a single task and use a loop to repeat the task with different packages one wants to install.
Most commonly an array is used to repeat a test with different values.
$packages = ['vim', 'git', 'curl']  

package { $packages: 
   ensure => "installed" 
}
Puppet supports most of the conditional structure which can be found in traditional programming languages. Condition can be used to dynamically define whether to perform a particular task or a set of code should get executed. Like if/else and case statements. Additionally, conditions like execute will also support attributes that works like condition, but only accepts a command output as a condition.
if $OperatingSystem != 'Linux' { 
   warning('This manifest is not supported on this other OS apart from linux.') 
} else { 
   notify { 'the OS is Linux. We are good to go!': }
} 
 Print
 Add Notes
 Bookmark this page