Puppet Type and Provider - Puppet (software)

What is Puppet Type and Provider?

Puppet sorts are used for individual configuration management. Puppet has different {types|differing types|differing kinds} like a service type, package kind, provider type, etc. whereby every kind has providers. The provider handles the configuration on completely different platforms or tools. as an example, the package kind has ability, yum, rpm, and DGM providers. There are loads of types and Puppet covers a decent spectrum configuration management item that has to be managed.

Puppet uses Ruby as its base language. All Puppet types and providers present are written in Ruby language. because it follows the standard encoding format, one will merely produce them as shown within the example for repo that manages repositories. Here, we are going to produce type repo and providers’ svn and git. the primary a part of the repo type is type itself. the kinds are sometimes stored in lib/puppet/type. For this, we are going to produce a file known as repo.rb.

$ touch repo.rb

Add the resulting content in the file.

In the above script, we have formed a block "Puppet::Type.newtype(:repo) do" which makes a new type with the name repo. Then, we have @doc which assists in adding whatever level of specifics one wants to add. The next statement is Ensurable; it creates a elementary ensures property. Puppet type uses ensure property to determine the state of configuration item.


The ensure statement tells Puppet to except three method: create, destroy, and exist in the provider. These methods offer the resulting features −s

  • A command to create a resource
  • A command to delete a resource
  • A command to check the existence of a resource

All we then need to do is require these procedures and their contents. Puppet creates the supporting infrastructure around them.
Next, we define a new parameter called source.

The basis will tell the repo type where to retrieve/clone/checkout the source repository. In this, we are also using a hook called validate. In the provider section, we have defined git and svn which check for the validity of the repository we have defined.

Lastly, in the code we have defined one more parameter called path.

This is the value type which stipulates where to put the new code that is retrieved. Now, again use the validate hook to create a block that checks the value of suitability.

Subversion Provider Use Case

Let’s start with the subversion provider using the above created type.

In the above code, we have sincere defined that we want fileutils library, require 'fileutils' which we are going to use method from.
Resulting, we have defined the provider as block Puppet::Type.type(:repo).provide(:svn) do which tells Puppet that this is the provider for type called repo.

Then, we have added desc which allows to add some documentation to the provider. We have also defined the command that this provider will use. In the next line, we are checking the features of resource like create, delete, and exist.

Creating a Resource

When all the above is done, we will create a resource which will be used in our classes and manifest files as shown in the resulting code.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Puppet (software) Topics