πΉ What is Puppet?
Puppet is an open-source configuration management and automation tool used to manage infrastructure at scale.
It helps you:
- Automate software installation
- Enforce system configuration
- Manage thousands of servers consistently
- Reduce manual repetitive tasks
Using Puppet, you define your server state in manifests (written in Puppet DSL), and Puppet ensures your system always stays in that state.
In this guide, weβll set up:
βοΈ Puppet Master
βοΈ Puppet Agent
βοΈ A demo module that installs NGINX and serves a custom webpage
All using AWS EC2 Ubuntu 22.04 instances.
Step 1: Launch Two AWS EC2 Instances
You need:
1 Puppet Master
1 Puppet Agent
Use Ubuntu 22.04 and open required ports (SSH, HTTP).
Step 2: Configure the Puppet Master (puppetmaster)
(Open your window powershell)
β SSH into master
ssh -i "C:\Users\User\Downloads\nagios.pem" ubuntu@15.206.178.143
Note: "C:\Users\User\Downloads\nagios.pem" is your nagios.pem file path and "15.206.178.143" is AWS EC2 instance of puppetmaster.
β Set hostname
sudo hostnamectl set-hostname puppetmaster
β Update /etc/hosts
sudo nano /etc/hosts
Add:
<ip-address-of-puppetmaster-ec2-instance> puppetmaster puppet
<ip-address-of-puppetagent-ec2-instance> puppetagent
Install Puppet Server
wget https://apt.puppet.com/puppet8-release-jammy.deb
sudo dpkg -i puppet8-release-jammy.deb
sudo apt update
sudo apt install puppetserver -y
β Enable + start service:
sudo systemctl enable puppetserver
sudo systemctl start puppetserver
sudo systemctl status puppetserver
Sign Agent Certificate (Will be used later)
sudo /opt/puppetlabs/bin/puppetserver ca list
sudo /opt/puppetlabs/bin/puppetserver ca sign -all
Step 3: Configure Puppet Agent (puppetagent)
(Open another window powershell)
β SSH into agent
ssh -i "C:\Users\User\Downloads\nagios.pem" ubuntu@3.108.65.97
Note: "C:\Users\User\Downloads\nagios.pem" is your nagios.pem file path and "15.206.178.143" is AWS EC2 instance of puppetagent.
β Set hostname
sudo hostnamectl set-hostname puppetagent
β Update /etc/hosts
sudo nano /etc/hosts
Add:
<ip-address-of-puppetmaster-ec2-instance> puppetmaster puppet
<ip-address-of-puppetagent-ec2-instance> puppetagent
Install Puppet Agent
wget https://apt.puppet.com/puppet8-release-jammy.deb
sudo dpkg -i puppet8-release-jammy.deb
sudo apt update
sudo apt install puppet-agent -y
Update Puppet Configuration (puppet.conf)
sudo nano /etc/puppetlabs/puppet/puppet.conf
Add:
[main]
certname = puppetagent
server = puppet
environment = production
βΆ Start Puppet Agent
sudo systemctl enable puppet
sudo systemctl start puppet
sudo /opt/puppetlabs/bin/puppet agent -t #this command send request for certificate signup to master
Step 4: Create a Puppet Module (sample_nginx)
sudo nano /etc/puppetlabs/code/environments/production/modules/sample_nginx
Folder Structure:
sample_nginx/
βββ manifests
β βββ nginx.pp
βββ templates
βββ index.erb
nginx.pp (Manifest File)
class sample_nginx::nginx {
package { 'nginx':
ensure => installed,
}
file { '/var/www/html/index.html':
ensure => file,
content => template('sample_nginx/index.erb'),
}
service { 'nginx':
ensure => running,
enable => true,
require => Package['nginx'],
}
}
Step 5: Update site.pp to Apply This Class
sudo nano /etc/puppetlabs/code/environments/production/manifests/site.pp
Add:
node default {
include sample_nginx::nginx
}
Step 6: Write Template File (index.erb)
<h1>Hello from Puppet NGINX!</h1>
<p>This is a custom page managed by Puppet.</p>
Step 7: Restart Master and Run Agent
On Master
sudo systemctl restart puppetserver
On Agent
sudo /opt/puppetlabs/bin/puppet agent -t
On Master
sudo /opt/puppetlabs/bin/puppetserver ca list
sudo /opt/puppetlabs/bin/puppetserver ca sign --all
If everything is correct:
β NGINX will be installed
β Custom page will appear at /var/www/html/index.html
β Puppet will manage service β auto-start + running
π Final Output
You can now visit:
π http://AGENT_PUBLIC_IP
You will see:
Hello from Puppet NGINX!
This is a custom page managed by Puppet.
Top comments (0)