Resources are essential unit to perform the system configuration. Each resource will describe the particular thing in puppet. For an example, specific user needs to be created or specific file needs to be updated across the puppet agent nodes. When you would like to manage the users, “user” resource type will come in to play. If you want to modify specific file, you need to use “file” resource type. To create a user , you need to provide set of attributes to define home directory , user id , group id , type of shell and comments. To define these attributes, you need to create a block of puppet code and this is called resource declaration. You must write these codes in “Declarative Modelling Language” (DML).
Let’s have look at the sample resource declaration code.
The above code consists following parts.
Resource Type – which in this case is “user“
Resource Title – which in this case is “oracle”
Attributes – these are the resource’s properties. (UID, GID, SHELL,HOME)
Values – this are the values that correspond to each properties.
Let’s apply the above resource declaration code on one of the puppet agent node.
Executing the Resource Declaration Code:
1.Login to the puppet agent node .
2. Apply the resource declaration code which we have created.
3.Navigate to directory “/etc/puppetlabs/code/environments/production/manifests” . (Not Mandatory)
4. Create a new file with name init.pp with following code.
5. Let’s apply the code using puppet command.
6. Verify our work.
We can see that oracle user is created as defined in the puppet code. At this point , we are not dealing with puppet Server/Master. We are just dealing with puppet agents on the client systems. Master/Server will come in to play when you would like to manage the things from centralized location (Which is the industry common practice). The above demonstration is just to understand that how puppet agent works.
To remove the resource , you just need to specify the resource name with “ensure=absent” value.
Verify the user again,
This is just an small example that how to define the resource with require attributes, create and delete it. In the above example, we have seen about “user” resource type. Let’s see that what are the in-built resource types available in puppet.
RESOURCE TYPE:
1. You view the available resource type using puppet command.
2. To know more about the specific resource type, use the following command with specific resource type.
Resource Abstraction Layer (RAL)
Each resource is belongs to specific resource type. Resources are described independently from the target operating system. It gives you enough information to the puppet server regardless of whether the puppet agent is a windows or Linux machine. Puppet agent allows you to view/manage all these resource via Puppet’s CLI interface Layer. (Ex: user creation , deletion )
The platform-specific-implementation exists in the form of “Providers” for each resource type. By default, in-built resource type will cover all Linux, Unix and windows platforms for each resource-type’s attribute. You can use the “describe” subcommand along with it’s “–providers” option to view a list of providers for each attribute for a given resource type. For an example, to view all the providers for the “service” resource type, use the following command.
Providers will be displayed in last section. Let me just bring up the “providers” part.
Here you can see that “service” resource type has different attributes for each OS family. Puppet agent handles these things in back-end.
Hope this article is informative to you. Share it ! Comment it ! Be Sociable !!!
The post Puppet – Resource Declaration – Overview appeared first on UnixArena.