How to use Puppet Manifests

How to use Puppet Manifests

In this tutorial you will learn how to use Puppet Manifests, to understand this tutorial you need to have an idea about manifests and resources also if you would like to learn about how to install Puppet follow this link.

 

To learn how to use Puppet manifests for automation will go through a simple life scenario, imagine that we have an infrastructure of 100 servers which are all connected to Puppet master and we need to change certain file in them and be sure that the Apache HTTPD is running.

Simple Puppet Manifest Example

In real life scenario there should be nodes which in them you should groups the servers into different groups so you can call specific groups whenever you want to make a change, in this simple example we are creating a simple site.pp manifest file to accomplish the previous goal.

vi /etc/puppt/manifests/site.pp

service {'httpd:
ensure => running,
enable => true,
'}

file {'/etc/blank':
content => 'This is a content example',
}

 

Applying Changes to Specific Node

If you want to apply the same above example to only specific node, simply add the following highlighted node argument before and after the resources.

node node1 {

service {'httpd:
ensure => running,
enable => true,
'}

file {'/etc/blank':
content => 'This is a content example',
}

}

Puppet Commands Tip

If you are not sure about available resources you can simply run below command to list all available resources.

Puppet resource --types "This will list available resources used in the server"

Or

Puppet describe list   "This will list available resources"

And for a specific resource help you can run:

Puppet describe package

You can also check all available options for specific resource

puppet resource file /etc/passwd

Above command will list all available options can be done for this resource:

Output:
file { '/etc/passwd':
ensure => 'file',
content => '{md5}4dcb685fdcdfd99d71750583a66703cf',
ctime => '2017-10-13 22:10:02 +0000',
group => '0',
mode => '644',
mtime => '2017-10-13 22:10:02 +0000',
owner => '0',
selrange => 's0',
selrole => 'object_r',
seltype => 'passwd_file_t',
seluser => 'system_u',
type => 'file',
}

 

Test Puppet Agent

Puppet agent -t

 

Change Puppet Agent Time Interval

Puppet agent by default check the master every 30 minutes, to change this you can simply edit /etc/puppet/puppet.conf and add the following to the [agent] section.

runinterval= 15m

This will change it to 15 minutes instead.

 


Subscribe to
for video tutorials updates