How to Setup Puppet Master and Agent on CentOS 7

Puppet is an open source configuration management tool and server automation framework. Puppet can run on Unix-like operating systems, as well as on the Microsoft Windows systems. It allows you to manage and perform administrative tasks and the configuration of hundreds of systems from one master server.

In this tutorial, I will you how to install Puppet on CentOS 7. I will install and configure a CentOS 7 server as a puppet 'master', and the other one as an 'agent'.

Prerequisites

  • 2 CentOS 7 servers
    • 10.0.15.10      master.hakase.io    2GB Memory
    • 10.0.15.11      agent.hakase.io
  • Root privileges

What we will do:

  1. Puppet Pre-Installation
  2. Install and Configure Puppet server
  3. Install and Configure Puppet Agent
  4. Verify Puppet Agent Configuration
  5. Create First Puppet Manifest

Step 1 - Puppet Pre-Installation

In this step, we will perform some tasks including installation and configuration on both servers puppet master and puppet agent. We will configure the host's file, synchronizing time using the NTP server, Disable SELinux, and add the puppet repository to the system.

- Configure hosts

Connect to the puppet master and agent using your root user.

ssh [email protected]
ssh [email protected]

Now edit the hosts using vim editor.

vim /etc/hosts

Add the following configuration to the end of the line.

10.0.15.10      master.hakase.io
10.0.15.11      agent.hakase.io

Save and exit.

Now test using the ping command.

ping master.hakase.io
ping agent.hakase.io

And make sure you get the server IP address 10.0.15.10 and 10.0.15.11.

Configure hosts file

- Configure NTP Server

It's very important to keep in synchronization the time between master and agent server.

Install the NTP packages on both servers using the yum command.

yum -y install ntp ntpdate

After the installation is complete, choose the NTP pool as you want by running the command as below.

sudo ntpdate 0.centos.pool.ntp.org

Now start the NTP service and enable it to launch everytime at system boot.

sudo systemctl start ntpd
sudo systemctl enable ntpd

NTP installation and configuration has been completed.

Configure NTP

- Disable SELinux

Edit the SELinux configuration using vim.

vim /etc/sysconfig/selinux

Change the SELINUX value to 'disabled'.

SELINUX=disabled

Save and exit.

- Add Puppet Repository

Now add the puppet repository to the system using the rpm command below.

rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm

Add puppet repository

When it is complete, reboot both servers.

reboot

Now we're ready for puppet installation and configuration.

Step 2 - Install and Configure Puppetserver

In this step, we will install the puppetserver on the master.hakase.io server. Install puppetserver using the yum command below.

sudo yum -y install puppetserver

After the installation is complete, we need to configure the memory allocation for puppetserver. We will set the max memory allocation for puppetserver to 1GB.

Edit the 'puppetserver' configuration using vim.

vim /etc/sysconfig/puppetserver

Now change the line as below.

JAVA_ARGS="-Xms1g -Xmx1g ...."

Save and exit.

Next, go to the puppet configuration directory and edit the 'puppet.conf' file.

cd /etc/puppetlabs/puppet
vim puppet.conf

Add the following configuration.

[master]
dns_alt_names=master.hakase.io,puppet

[main]
certname = master.hakase.io
server = master.hakase.io
environment = production
runinterval = 1h

Save and exit.

Now start the puppetserver and enable it to launch everytime at startup.

systemctl start puppetserver
systemctl enable puppetserver

The Puppetserver installation and configuration has been completed successfully.

Configure puppetserver

If you're using firewalld on your system, add the puppetserver port to the list using the firewall-cmd command below.

firewall-cmd --add-port=8140/tcp --permanent
firewall-cmd --reload

Configure firewall

Step 3 - Install and Configure Puppet Agent

We will install the puppet agent on the 'agent.hakase.io' server.

Install puppet agent using the yum command below.

yum install -y puppet-agent

After the installation is complete, go to the puppet configuration directory and edit the puppet.conf file.

cd /etc/puppetlabs/puppet
vim puppet.conf

Paste the following configuration.

[main]
certname = agent.hakase.io
server = master.hakase.io
environment = production
runinterval = 1h

Save and exit.

Next, we will register the puppet agent to the puppet master.

Run the command below on the puppet agent shell.

/opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true

The puppet agent is now running on the server, and it's attempting to register itself to the puppet master.

Now back to the puppet master shell and run the command below.

/opt/puppetlabs/bin/puppet cert list

And you will get the pending Certificate Signing Request (CSR) from the puppet agent server 'agent.hakase.io'.

Sign the certificate using the command below.

/opt/puppetlabs/bin/puppet cert sign agent.hakase.io

And the result should be similar to the following:

Configure puppet agent

The puppet agent is now running on the system, and the certificate for the agent has been signed by the puppet master.

Step 4 - Verify the Puppet Agent Configuration

After the puppet master signed the certificate file for the agent, run command below on the puppet agent to verify the configuration.

/opt/puppetlabs/bin/puppet agent --test

And you will get the result as shown below.

Verify puppet agent configuration

The Puppet agent pulled the configuration from the puppet master and applied to the server without any error.

Step 5 - Create First Manifest

The puppet master and agent installation and configuration have been completed. And for this step, we will create a simple manifest for testing.

We will create the manifest for Apache httpd web server installation.

On the puppet master server, go to the '/etc/puppetlabs/code/' directory and create the new manifest file 'site.pp' using vim.

cd /etc/puppetlabs/code/
cd environments/production/manifests

Create new manifest file.

vim site.pp

Paste the following configuration.

node 'agent.hakase.io' {
    package { 'httpd':
        ensure  => "installed",
    }
    service { 'httpd':
        ensure => running,
    enable => true
    }
}

Save and exit.

Now open the puppet agent server shell and run the command below.

/opt/puppetlabs/bin/puppet agent --test

The command will retrieve new manifest configuration file from the puppet master and then apply it to the agent server.

Following is the result.

Create puppet manifest

Open your web browser and type the IP address of the puppet agent.

http://10.0.15.11/

And you will get the default HTTP page as below.

Apache test page

The httpd web server has been installed using the puppet manifest.

Installation and configuration of the Puppet Master and Puppet Agent on CentOS 7 has been completed successfully.

Reference

Share this page:

Suggested articles

2 Comment(s)

Add comment

Comments

From: pida42 at: 2018-06-13 11:43:00

Would be nice to keep SeLinux enabled and create rules instead of disabling it...

From: Essakhi at: 2018-06-28 13:53:22

Thanks. It helps me. Great.