Configuration Management Tools DevOps

Install Puppet Master Server & Puppet Agent on CentOS 7 / RHEL 7

puppet_trail

This tutorial describes you step by step procedure to install and configure puppet master and puppet agent on Linux (CentOS7 / RHEL7).
And install httpd through puppet.

Our Instance Setup:

i am using Digital Ocean Server you can use local server
Description              Master node                              Client node
Operating System      CENTOS 7 – 64 Bit                       CENTOS 7 – 64 Bit
Host Names                batmobile.guesslinux.com          puppettest.guesslinux.com
IP Address                   139.59.74.153                                139.59.74.250

1

Make sure both server are accessible.
Make an entry of each host in /etc/hosts for name resolution on both nodes as below or Configure

vi /etc/hosts on both nodes

guesslinux_puppet1 guesslinux_puppet2

Disable firewall on both nodes if enabled to avoid any issues during the configurations.

guesslinux_puppet3

Step 1: Install puppetlabs repository on both nodes
Update the packages and install the puppetlabs repo using the below command.

yum -y install http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm

yum -y update

guesslinux_puppet4

guesslinux_puppet5

 

Step 2: Install required package on the master node mine is batmobile

yum -y install puppet-server

guesslinux_puppet6

guesslinux_puppet7

Step 3: Configure the puppet master server

/etc/puppet/puppet.conf is the Puppet Configuration file, edit the file to define the friendly dns hostnames and certificate name for the puppet master node in the [main] section.

vi /etc/puppet/puppet.conf

guesslinux_puppet8

guesslinux_puppet9

Step 4: Generate the certificate from the puppet master node

After executing the below command to generate the certificate, press “CTRL + C” to cancel when you see the puppet version as below and start the “puppetmaster” service.

sudo -u puppet puppet master --no-daemonize --verbose

guesslinux_puppet10

guesslinux_puppet11

guesslinux_puppet12

Start and enable the puppetmaster service.

systemctl start puppetmaster && systemctl enable puppetmaster

guesslinux_puppet13

Install Puppet agent packages on the client node in my case its puppettest

yum -y install puppet

guesslinux_puppet15

guesslinux_puppet16

Step 6: Configure the puppet agent on the client node

Again /etc/puppet/puppet.conf is the Puppet Configuration file, edit the file to define the puppet master node in the [agent] section.

vi /etc/puppet/puppet.conf

guesslinux_puppet17

guesslinux_puppet18

Step 7: Generate the signing request certificate from the puppet agent node puppettest

puppet agent -t

guesslinux_puppet19

Step 8: List the certificates to be signed from the puppet master node “batmobile” and sign it.

guesslinux_puppet20

puppet cert sign puppettest.guesslinux.com

guesslinux_puppet21

guesslinux_puppet22

Start and enable the puppet agent service.

systemctl start puppet && systemctl enable puppet

guesslinux_puppet23 copy

Step 9: Verify the certificate signed properly with the puppet master node?

guesslinux_puppet24

Thats all about Puppet master and puppet agent installation and configuration.

its time for test.

  1. Test one create file on agent server
  2. Test two install apache and uninstall it

Testing

create puppet manifest file using following, all config file should be but under /etc/manifests/ folder

vi /etc/puppet/manifests/site.pp

guesslinux_puppet25

add the following code

node "puppettest.guesslinux.com" {
file {
'/root/seema.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for seema1",
}

file {
'/root/bebe.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for bebe",
}
}

 

guesslinux_puppet26

and on agent check the file and type

puppet agent -t

guesslinux_puppet27

guesslinux_puppet28

guesslinux_puppet29

by default puppet agent pull the config file in a interval of 30 minutes means 1800 seconds, changed it to 2 seconds for testing purpose.

puppet agent --configprint runinterval

guesslinux_puppet30

vi /etc/puppet/puppet.conf

guesslinux_puppet31

on line number 29 add

runinterval = 2

guesslinux_puppet32

check run interval

guesslinux_puppet33

ITS TIME TO INSTALL HTTPD AND TEST

add the following code to /etc/puppet/menifests/site.pp

node "puppettest.guesslinux.com" {
file {
'/root/seema.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for seema1",
}

file {
'/root/bebe.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for bebe",
}

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

}

guesslinux_puppet34

on agent check apache status

guesslinux_puppet35 guesslinux_puppet36

open your agent ip on browser

guesslinux_puppet37

Its time to uninstall apache using puppet

add the following code to

vi /etc/puppet/manifests/site.pp
node "puppettest.guesslinux.com" {
file {
'/root/seema.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for seema1",
}

file {
'/root/bebe.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "700",
content => "Congratulations! Puppet has created this file for bebe",
}
}

package {
'httpd':
ensure => purged,
require => Service["httpd"],
}

service {
'httpd':
ensure => stopped,
enable => false,
}
}

guesslinux_puppet38

check apache status on puppet agent

guesslinux_puppet39

guesslinux_puppet40

 

Thank You

 

Leave a Comment