Puppet Resources-II

In continuation to Puppet Resource, lets extend the information gained in the previous post to some more real time examples.


Lets create a “package” and “user” Puppet Codes using Core Puppet Resource types in the same way we have created file using “file” Resource type last time in Puppet Resource post. Lets see the best approach to create a Puppet Code for Package and User.

1.) First step is to find out the available resource types in Puppet:

puppet help resource
puppet resource –types

We will find “package and user” Resource Types along with many other inbuild/core Resource Types.

2.) Second step is to find out the list of attributes to use with the available Puppet Resource Types, puppet provide users with useful utilities which helps and saves lot of time.

puppet describe <Resource Type>
puppet describe package
puppet describe user

This will provide us with all of the attributes which can be used with the Resource Type to create puppet codes.

3.) Follow the Puppet code creation syntax, Every Puppet resource is having three parts which we have to declare while creating any puppet code. For more details check our previous Puppet Resource post:

Resource Type
Resource Tittle
Resource Attributes

4.) Go to the working environment directory, so far we are taking the simple configuration without modules so for us it would be “/etc/puppetlabs/code/environment/production/manifests” (Check previous posts for more details on puppet.conf). Create two file with .pp extention and write your Puppet Code for package and user. Below are some example but you can use any of the attributes to learn more.

package { ‘ntp’:
ensure => ‘present’

Note: This will install “ntp” package if not already installed on the system otherwise it will not do anything.

user { ‘thinknyx’:
ensure => ‘present’,
group => ‘root’,
owner => ‘root’,
home => ‘/home/thinknyx’,
managehome => ‘true’

Note: This will create a user called “thinknyx” with the mentioned attributes or will drift the changes as per attributes if user already exists.

In similar way you can do practice with any core type resource to get more familiar with the basic building blocks. In our next post we will check the code syntax and will run the puppet code to see its functioning.

Leave a Comment

Your email address will not be published.