Puppet – Automating Infrastructure Configuration

ZenvilaZenvila
4 min read

What is Puppet?

Puppet is an open-source configuration management tool that automates the provisioning, configuration, and management of infrastructure. It ensures that your systems are configured consistently and correctly according to predefined policies.

Why is Puppet a Configuration Management Tool?

  • Automates Setup: Ensures systems are consistently configured.

  • Infrastructure as Code: Uses a declarative language to define configurations.

  • Consistency: Enforces policies across systems, reducing configuration drift.

Use Cases

  • Provisioning: Automate setup of new servers.

  • Configuration: Maintain consistent system configurations.

  • Deployment: Automate software installations and updates.

  • Compliance: Ensure systems meet regulatory standards.

Dependencies

  • Puppet Agent: Installed on managed nodes.

  • Puppet Master: Central server distributing configurations.

  • Modules/Manifests: Code defining resource states.


Setting Up Puppet

To set up Puppet, you need a master server (Puppet Master) and one or more agent servers (Puppet Agents). Here’s a simplified guide:

Initial Setup

Update your repositories:

         sudo apt update
     sudo apt upgrade
  1. Install Docker:

     sudo apt install docker.io
    

    Pull the Puppet image:

    sudo docker pull puppet
    

    Create the Puppet Master container:

     sudo docker run --name puppet-master -it puppet7
    

    Start the Docker service:

      sudo systemctl start docker
    

    Run the Puppet Master container:

    sudo docker start puppet-master
    

    Check if the container is running:

  2.  sudo docker ps -a
    

    Installing Puppet Server:

  3.   apt install puppetserver
    

    Enter the container and install necessary utilities:

     apt install vim net-tools
    

    If you encounter issues with broken packages, run the following commands:

  4.   apt update && sudo apt upgrade
    
  5. comm : apt --fix-broken install

  6.   apt clean
    
    1.  apt autoremove && sudo apt-get autoremove
      
  1.   apt-get install puppet-agent
    
  1.  apt-get install puppet-module-puppetlabs-mailalias-core
    
  1.  apt-get install puppetserver
    
  1. else

    Check the Java version:

      java -version
    

    (Note : Adjust Java configuration if necessary to manage system memory usage)

    Check Puppet service:

      netstat -ntulp
    

    (If you see port 8140, it means Puppet is listening to all ports.)

    Set up the Certificate Authority:

       /opt/puppetlabs/bin/puppetserver ca setup
    

    **

    Check system information:**

      facter -p
    

    Find the Fully Qualified Domain Name (FQDN):

      facter -p | grep fqdn
    

    Create a .pp file for Puppet configurations:

       puppet apply filename.pp
    

Creating the Puppet Agent

Create the Puppet Agent container using the same image:

      sudo docker run --name puppet-agent01 -it puppet

(Note : Start and run the Puppet Agent container as described earlier)

Install Puppet Agent in the container:

      apt install puppet-agent

Establishing Communication

Update /etc/hosts with IP and FQDN:

     vi /etc/hosts  (Note: Add the IP and FQDN at the end of the file)

Run commands in the Puppet Agent container to establish communication with the master:

      /opt/puppetlabs/bin/puppetserver ca setup

In the Puppet Master container, configure autosign in /etc/puppetlabs/puppet/puppet.conf:

autosign = true

In the Puppet Agent container, test the connection to the Puppet Master:

  1.      puppet agent --test puppet_masterfqdn
    

    Managing Puppet Policies for both(master & agent )

    In the Puppet Master container, navigate to:

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

    (Note : In this directory create this file )

    Create init.pp and site.pp files to define policies and configurations.

    In the Puppet Agent container, run the following command to apply policies from the master:

    To run again you have to run this command again and again :

      puppet agent --test puppet_masterfqdn
    

    P.S.

    If you spot any mistakes, please don't hesitate to point them out. We're all here to learn together! 😊

    Haris
    FAST (NUCES)
    BS Computer Science | Class of 2027

    📌 GitHub: https://github.com/Zenvila
    📌 LinkedIn: https://www.linkedin.com/in/haris-shahzad-7b8746291/
    📌 Member: COLAB (Research Lab)

0
Subscribe to my newsletter

Read articles from Zenvila directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Zenvila
Zenvila

I'm Haris aka Zen, currently in my 4th semester of Computer Science at FAST-NUCES and a member of COLAB (Research Lab) in Tier 3. I'm currently exploring AI/ML in its early stages, and also focusing on improving my problem-solving techniques. 🐧 Proud user of Arch Linux | Command line is my playground. I'm interested in Automation & Robotics Automation enthusiast on a mission to innovate! 🚀 Passionate about turning manual tasks into automated brilliance.