How to Install and Configure Puppet on CentOS 7

Installation and Configuration of Puppet on Redhat 9/Redhat 8/Redhat 7/CentOS 8/CentOS 7

Puppet is an open source and enterprise configuration management tool in DevOps. Puppet is use to configuring and managing the puppet client machines that is connect with the puppet server by use of puppet agent. The puppet use languages are Ruby DSL (domain-specific language) and puppet language. The supported platform of puppet are Microsoft Windows, Debian/Ubuntu, Red Hat/CentOS/Fedora and MacOS X.  The configurations that manage the puppet clients save on a puppet server is “config repository”, configuration has written in compiled format (catalog). The files have a configuration that applied on a puppet client machine is called “manifest”, the manifest files extension is “.pp”. The manifest file will create on directory location “/etc/puppet/manifests”, as per need multiple manifests file are create for single purpose is called a module. The module must have readme file with a basic description that how to use this module and module should have metadata.json file that containing version, dependencies, information and intended operating systems. To define resources (files, users, groups, command, packages etc.) on puppet code classes are also use to organize code better and reuse the code with the help of classes easily. The puppet master server connect with puppet client machine through puppet agent, agent take all the information from puppet master server by use of catalog then deploy the configuration on a puppet client machine. Puppet master server use port 8140 to allow puppet client machine to take the information from puppet master server by use of puppet agent. Puppet client node (agent node) contact with the Puppet master server in every 1800 seconds to take updated configurations (puppet codes) for execute the necessary tasks. Puppet client node (agent node) communicate with the Puppet master server through secure certificate.

Puppet is a leading tool of DevOps as compare to Chef to automate the process for packages installation, server setup, system management (users, groups, services) etc. Puppet is a software that allow system administrator and developer work together. By use of puppet developer build, test and launch the application without the need of system administrator that allocate the resources.

Types of Puppet: There are the two types of puppet available for system management to automate process of configuration centrally.
Open source Puppet: Open source puppet is a free software that download from the puppet website freely and deployed on a Linux base operating system (RedHat/CentOS/Fedora and Debian/Ubuntu) with some easy steps.
Enterprise Puppet: This version have cost to provide services and features like command-line tools, compliance reporting, role-based access control, GUI, API, and orchestration.

Benefit of Puppet: Puppet is based on Infrastructure as code that resolve issue through continuous delivery and automated deployment. Puppet also have platform that is open source developer community, where free puppet codes are available on different scenarios.

The lab scenario are based on two machine on domain environment “pakistan.local1”, details are mention below.
192.168.10.11                   puppetmasterserver.pakistan.local1
192.168.10.226                 lamp.pakistan.local1

Note: stop and disable the service “firewalld” and set the selinux in permissive mode.

Puppet Server Machine: To install the Puppet server on server machine first enable the repository on server machine. To enable the repository on Redhat/CentOS/Fedora, type the below mention command.

For RedatHat 7
yum install http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm -y
or
yum install http://yum.puppetlabs.com/puppet-release-el-7.noarch.rpm -y
For RedatHat 8
dnf install https://yum.puppetlabs.com/puppet-release-el-8.noarch.rpm -y
For RedatHat 9
dnf install https://yum.puppetlabs.com/puppet-release-el-9.noarch.rpm -y

how to install and configure puppet master with puppet agent on redhat 8

After enable the puppet repository verify the repository files are available on directory “/etc/yum.repos.d/” of related operating system (Redhat 9/Redhat 8/Redhat 7/CentOS 8/CentOS 7). To verify the puppet repository files are available type the below mention command.

ls -lrt /etc/yum.repos.d/  

To install the package “puppet-server” on puppet server, type the below mention command.

yum install puppet-server -y

To modify the main configuration file of puppet, modify the file on directory location “/etc/puppet/puppet.conf” by use of editor “vi”.

vi /etc/puppet/puppet.conf

Provide the dns alt name and certificate name on main configuration file of puppet “/etc/puppet/puppet.conf”, this lab is perform in domain environment “pakistan.local1”.

dns_alt_names=puppet,puppet.pakistan.local1,puppetmasterserver.pakistan.local1
certname = puppet 

how to install and configure puppet master with puppet agent on redhat 8

To generate the certificate on puppet master server, type the below mention command.

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

how to install and configure puppet master with puppet agent on redhat 7

To start, enable and check the status of service “puppetmaster” on puppet server, type the below mention command.

systemctl start puppetmaster
systemctl enable puppetmaster
systemctl status puppetmaster

Puppet Client Machine: To install the Puppet on client machine first enable the repository on client machine. To enable the repository on Redhat/CentOS/Fedora, type the below mention command.

For RedatHat 7
yum install http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm -y
or
yum install http://yum.puppetlabs.com/puppet-release-el-7.noarch.rpm -y
For RedatHat 8
dnf install https://yum.puppetlabs.com/puppet-release-el-8.noarch.rpm -y
For RedatHat 9
dnf install https://yum.puppetlabs.com/puppet-release-el-8.noarch.rpm -y

To install the puppet agent on client machine, type the below mention command. Puppet agent is used to communicate puppet client machine with the puppet server machine for centrally manage the catalog configurations that apply from puppet master server to puppet client machine.

yum install puppet -y

Modify the puppet configuration file on client machine by use of editor “vi”, the puppet configuration file is availaible on directory location “/etc/puppet/puppet.conf”.

vi /etc/puppet/puppet.conf

Add the server IP address or hostname or fully qualified domain name on client machine puppet configuration file in Agent area.

server = puppetmasterserver.pakistan.local1
how to install and configure puppet master with puppet agent on redhat 7

After modify the puppet configuration file on client machine, start and enable the service “puppet” by type the below mention command.

systemctl start puppet
systemctl enable puppet

Server Machine: To sign the puppet client machine certificate on puppet server machine, first list the certificate then sign the certificate by type the below mention command.

puppet cert list
puppet cert sign lamp.pakistan.local1
puppet cert sign --all

how to install and configure puppet master with puppet agent on redhat 9

This is the acknowledge or sign the client certificate. Connection between the puppet master and agent has been establish.
Client Machine: To verify the certificate sign properly from puppet master node to puppet client node, type the below mention command.

puppet agent --fingerprint

how to install and configure puppet master with puppet agent on redhat 9

Client Machine: To manually Retrieving plugin facts and applying catalog configuration, type the below mention command.
puppet agent -t
Here we are work on some examples that apply configuration from puppet master server to puppet client machines through manifest files. First we create/modify default puppet file "site.pp" on directory location "/etc/puppet/manifests" by use of editor "vi".
vi /etc/puppet/manifests/site.pp
Example 1: Start or Stop with Enable or Disable any service from puppet master server to puppet client machine (puppet agent install machine).
Code for start with enable any service, here the code is available for start and enable apache web service "httpd". You can change the code as per your need in terms of service.
node default {
service { 'httpd':
  ensure => 'running',
  enable => 'true',
}
}
Code for stop with disable any service, here the code is available for stop and disable apache web service "httpd". You can change the code as per your need in terms of service.
node default {
service { 'httpd':
  ensure => 'stopped',
  enable => 'false',
}
}
Example 2: You can apply configuration from puppet master server to puppet client machines by the help of puppet module. you can download the puppet module from Puppet forge website directly or install on puppet master server if the puppet master server has internet connectivity. Here we have given an example of module  "vim". 
Install downloaded Puppet Module:
puppet module install /owais/abc.tar.gz
or
puppet module install /owais/vim
Install Puppet Module through Internet:
puppet module install vim
To define the puppet module "vim" on default puppet manifest file "site.pp" on directory location "/etc/puppet/manifests/site.pp", type the below mention command.
vi /etc/puppet/manifests/site.pp
Edit the below mention code to install puppet module "vim" on all puppet client machine from puppet master server.
node default {
class { 'vim':
}
}
Edit the below mention code to install puppet module "vim" on specific puppet client machines from puppet master server. Here we are give an example for two hosts (host1 and host2) that have dns entry on DNS server or host entry on puppet master server and puppet client machine hosts file on directory location "/etc/hosts".
node 'host1', 'host2' {
class { 'vim':
}
}
To Search that how many module is install on you puppet master machine, use the below mention command. This command output show that how many puppet module has installed on directory location "/etc/puppet/modules" and "/usr/share/puppet/modules". 
puppet module search vim
Example 3: The third is a great example to work with puppet. The best way to define configuration that will apply from puppet master server to puppet client machine is to create module on directory location "/etc/puppet/modules" for each configuration that will apply from puppet master server to puppet client machines. Means here we create a module for package "postfix". For this we create a directory "postfix" inside a module directory location "/etc/puppet/modules" by use of command "mkdir".
mkdir /etc/puppet/modules/postfix
Then we will create a directory "manifests" in the directory location "/etc/puppet/modules/postfix" by use of command "mkdir".
mkdir /etc/puppet/modules/postfix/manifests
Finally create a file "init.pp" in the directory location "/etc/puppet/modules/postfix/manifests" by use of command "vi". 
vi /etc/puppet/modules/postfix/manifests/init.pp
Edit the below mention code in file "init.pp".
class postfix {
#Intall Postfix (mail server) Package
package {'postfix':
 ensure => present,
}
#Postfix service enable and running
service {'postfix':
 ensure => running,
 enable => true,
}
}
Finally to apply module "postfix" configuration on puppet client machines from puppet master server, call this module "postfix" that define as a class on main default puppet manifest file "site.pp".
node default { }
node 'host1', 'host2' {
include postfix
}
In the above example 3 modules directory must have module directory name "postfix" that similar to class name "postfix" and in the module directory "postfix" must have directory "manifests" that must have a file "init.pp" where the configuration is define for module. This is a great way to push configurations from puppet master server to puppet client machines where each and every module separately define then finally call on main default puppet manifest file "site.pp".
 
To check or verify the puppet manifest file have a correct puppet syntax use the below mention command, it will provide you the information the manifest file that have file extension ".pp" is correct or not.
puppet parser validate site.pp
To list all the puppet resources that puppet is providing for manage the puppet client machine from puppet master server, type the below mention command.
puppet resource --types
Below are the command of puppet resources for (service "postfix", file "/etc/hosts", mount point "/apps",user "owais") that will give the current status of resources on puppet server machine or puppet client machine (agent machine).  
puppet resource service postfix  
puppet resource file /etc/hosts
puppet resource mount /apps
puppet resource user owais
If you want some details of puppet resources (service, cron, file, mount and etc) that what is that and what is the purpose of the resource, you can use the below mention command it will give you the some description about the resources.
puppet describe --list
or
puppet describe file
By default puppet configuration is applied from puppet master server to puppet client machine in 30 minutes, you can change this time duration as per your requirement to modify the file "puppet.conf" on directory location "/etc/puppet/puppet.conf" in agent area edit the below mention configuration, for all puppet client set this configuration on puppet master server or you can set this configuration for specific puppet client machine on the same directory location file "/etc/puppet/puppet.conf".
runinterval = 15m
Thanks for Read this Article

Comments