Linux

How to Install and Use Puppet on Linux

How to Install and Use Puppet on Linux

Puppet is a widely-used configuration management tool that automates the administration of your infrastructure. It simplifies repetitive tasks, ensuring consistency across servers by defining and enforcing desired states. Puppet is particularly beneficial for system administrators managing large environments, as it reduces the risk of human error and increases efficiency. In this guide, you will learn how to install and use Puppet on a Linux system.

What is Puppet?
Puppet is an open-source tool that allows you to define infrastructure as code (IaC). With Puppet, you can manage configuration files, install software, and deploy services automatically across multiple systems. Puppet uses a declarative language to define system states, making it easier to maintain system consistency, even at scale.

Puppet Components
Puppet comprises two main components:

Puppet Master: This is the central server that holds the desired state of the systems (nodes) managed by Puppet.
Puppet Agent: This is installed on the nodes (servers) that communicate with the Puppet Master to receive and apply configurations.
Prerequisites
Before installing Puppet, make sure your system meets the following requirements:

A Linux server (preferably Ubuntu or CentOS) with root or sudo access.
Internet access for downloading and installing Puppet packages.
Basic knowledge of Linux commands.
Installing Puppet on Linux
Let’s walk through the installation process of Puppet on a Linux system. The steps outlined below apply to both Puppet Master and Puppet Agent.

Step 1: Add Puppet Repositories
First, you need to add the official Puppet repository to your system’s package manager. This ensures that you get the latest version of Puppet.

For Ubuntu/Debian:
Open the terminal and run the following command to add the Puppet repository:

curl -O https://apt.puppetlabs.com/puppet7-release-focal.deb
sudo dpkg -i puppet7-release-focal.deb
sudo apt update

For CentOS/RHEL:
Run the following command to add the Puppet repository:

sudo rpm -Uvh https://yum.puppetlabs.com/puppet7-release-el-7.noarch.rpm
sudo yum update

Step 2: Install Puppet
Once the repository is added, you can install Puppet using your package manager.

For Ubuntu/Debian:

sudo apt install puppet-agent -y

For CentOS/RHEL:

sudo yum install puppet-agent -y

This command installs both the Puppet Master and Puppet Agent on your system. You can configure them based on your needs.

Step 3: Configure Puppet Master
Once Puppet is installed, you need to configure the Puppet Master. The configuration files for Puppet are located in /etc/puppetlabs/puppet/. The primary configuration file is puppet.conf.

To start configuring the Puppet Master, follow these steps:

Edit the Puppet Master Configuration File:

Open the puppet.conf file for editing:

sudo nano /etc/puppetlabs/puppet/puppet.conf

Add the following configuration:

[main]
certname = puppetmaster.example.com
server = puppetmaster.example.com
environment = production

Replace puppetmaster.example.com with your actual Puppet Master hostname.

Start Puppet Server:

Start the Puppet Master service using the following command:

sudo systemctl start puppetserver

Enable Puppet Server to Start on Boot:

sudo systemctl enable puppetserver

The Puppet Master is now running and ready to manage Puppet Agents.

Step 4: Configure Puppet Agent
To configure Puppet Agent on a node, you need to edit its puppet.conf file. The configuration file for Puppet Agent is also located in /etc/puppetlabs/puppet/.

Edit the Puppet Agent Configuration File:

sudo nano /etc/puppetlabs/puppet/puppet.conf

Add the following lines:

[main]
certname = agent.example.com
server = puppetmaster.example.com
environment = production

Replace agent.example.com with your node’s hostname and puppetmaster.example.com with your Puppet Master’s hostname.

Start the Puppet Agent:

Run the following command to start the Puppet Agent:

sudo systemctl start puppet

Enable Puppet Agent to Start on Boot:

sudo systemctl enable puppet

Step 5: Sign Puppet Agent Certificate on the Puppet Master
After configuring the Puppet Agent, it will automatically generate a certificate signing request (CSR) and send it to the Puppet Master. You need to sign this CSR on the Puppet Master before the Agent can communicate.

List the Pending Certificates:

On the Puppet Master, run the following command to view pending CSRs:

sudo /opt/puppetlabs/bin/puppetserver ca list

Sign the Certificate:

To sign the certificate for the agent node, use the following command:

sudo /opt/puppetlabs/bin/puppetserver ca sign –certname agent.example.com

Replace agent.example.com with the actual hostname of the Puppet Agent.

Step 6: Create Puppet Manifests
A manifest is a file that defines the desired state of a system, using Puppet’s declarative language. Manifests are stored in the /etc/puppetlabs/code/environments/production/manifests/ directory on the Puppet Master.

Create a Simple Manifest:

Let’s create a simple manifest that ensures the ntp package is installed on all agents:

sudo nano /etc/puppetlabs/code/environments/production/manifests/site.pp

Add the following content:

node ‘default’ {
package { ‘ntp’:
ensure => installed,
}
}

Apply the Manifest:

Puppet Agents automatically check in with the Puppet Master periodically (typically every 30 minutes) to apply manifests. However, you can trigger a manual check using the following command on the agent:

sudo /opt/puppetlabs/bin/puppet agent –test

Step 7: Verify Puppet is Working
To ensure that everything is working correctly, check the status of Puppet on both the master and agent nodes:

On Puppet Master:

sudo systemctl status puppetserver

On Puppet Agent:

sudo systemctl status puppet

If both services are running, Puppet should now be managing your infrastructure automatically

Puppet Docs

Thank you for reading our article! If you’re interested in learning more about Linux systems, Terraform, and Chef, feel free to check out the link below. 🙂

How to Install Chef on Ubuntu

How to Install and Use Terraform on Linux

If you’re aiming to enhance your server skills, check out these packages by selecting a reliable and suitable server from our site. Best of luck! 🙂

Bulgaria Location Virtual Dedicated Server

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button