• Articles
  • Tutorials
  • Interview Questions

Puppet Cheat Sheet

Puppet User Handbook

Are you a programmer looking for a powerful tool to manage your servers? If yes, then you must take Puppet into consideration.

This Puppet cheat sheet is designed for those who have started their journey with Puppet and need a handy reference to implement what they have learned in real-time.

You can also download the printable PDF of this Puppet cheat sheet

Puppet Cheat Sheet

In the early days of software development, everything was done manually such as inspecting, operating, and delivering applications. Later on, different phases of SDLC started getting automated, and it is there Puppet came into the picture.

Puppet is an open-source configuration framework. It is a tool that gives an automatic way of inspecting, delivering, and operating applications faster. It helps in discovering content in cloud, containers, and on-premises systems and what software runs on them.

Watch this Puppet Tutorial for Beginners:

Video Thumbnail
Youtube subscribe

What is Puppet?

It is an open-source system management tool used for automating configuration management, a detailed recording and updating of information that describes the enterprise software and hardware.

This configuration framework is useful:

  • When we have a lot of machines needed to be configured in a similar way
  • When we have an infrastructure that requires dynamic scaling up/down with pre-determined config
  • To have control over all the config machines so that a centralized change gets propagated

Certification in Cloud & Devops

Puppet Architecture

Further, in this tutorial, we will look into the architecture of Puppet. The below image shows the components and workflow of Puppet:

Puppet Architecture

  • Node: It consists of a block of Puppet code.
  • Puppet Master: It is the master node that controls the flow and has the authority.
  • Catalog: It is a document describing the state of resources on a node, which is managed by Puppet.
  • Report: It is a record of the actions and infrastructure applied by a catalog during a Puppet run

Files

In Puppet, all programs, written in any programming language, are stored in a file that is used to manage directories and symlinks.

Attributes:

  • Ensure if the file exists or not and what it should be. Allowed:
    • File
    • Directory
    • Link
    • Present
    • Absent
  • Normal files:
    • Source: The source of a file
    • Content: The desired content as a string
  • Directories:
    • Source: The source of a file
    • Recurse: Whether to recursively manage the files in the directory
    • Purge: Whether the unmanaged files in the directory should be deleted
  • Symlinks:
    • Target: The symlink target
  • Others: backup, checksum, force, ignore, links, and replace

Get 100% Hike!

Master Most in Demand Skills Now!

Package

It is used to manage software packages.

Attributes:

      • Name: The name of the package
      • Ensure if it should be installed or not
      • Present
      • Latest
      • Absent
      • Purged
      • Source: Where to obtain the package
      • Provider: Which packaging system to use

Service

It is used to perform routine maintenance.

Attributes:

    • Name: The name of the service to run
    • Ensure the status whether it is running or stopped
    • Enable: If it should start on boot
    • Hasrestart: Whether to use the init script restart command instead of stop+start
    • Hasstatus: Whether to use the init script status command

Become a Cloud and DevOps Architect

Classes and Modules

Classes:

Defining classes makes the class available by its name but not by the code inside. Declaring a class evaluates the code inside too.

class my_class {
... puppet code ...
}
include my_class

Modules:

By stowing the implementation of a feature in a module, our main manifest can become much smaller, more readable, and policy-focused.

Module structure:

    • A module is a directory.
    • Module and directory names have to be the same.
    • A module contains the manifest directory (contains .pp files).
    • It should contain the init.pp file.

Puppet CLI

Puppet CLI consists of a single Puppet command with multiple sub-commands.

  • Bootstrap client: Tasks that bootstrap or install Puppet on the agent node
puppet agent -t --server <puppet master> [<options>]
  • Displaying facts:
facter              # All system facts
facter -p           # All system and Puppet facts
facter -y           # YAML
<em>facter -j           # JSON
facter [-p] <name>  # A specific fact</em>
  • Injecting facts:
env FACTER_= puppet apply site.pp
  • Finding out effective classes on a node:
cat /var/lib/puppet/classes.txt
  • Finding out the file modification date:
cd /var/lib/puppet
for i in $(find clientbucket/ -name paths); do
echo "$(stat -c %y $i | sed 's/..*//')       $(cat $i)";
done | sort -n
  • Disabling and enabling Puppet agent:
puppet agent --disable
puppet agent --disable <info message> #Only recent versions
puppet agent --enable
  • Managing certificates:
puppet cert list
puppet cert list --all
puppet cert sign <name>
puppet cert clean <name> #Removes cert
  • Managing nodes:
puppet node clean <name> #Removes node + cert
  • Managing modules:
puppet module list
puppet module install <name>
puppet module uninstall <name>
puppet module upgrade <name>
puppet module search <name>

Watch this interesting video on Puppet Installation:

Video Thumbnail
Youtube subscribe
  • Inspecting resources and types:
puppet describe -l
puppet resource <type name>
puppet kick <name>
puppet kick -p 5 <names> #To trigger puppet from master
  • Debugging and deploying:
puppetd --test #To enable standard debugging options
puppetd --debug #To enable full debugging
puppetd --one-time --detailed-exitcodes #To enable exit codes
# 2=changes applied
# 4=failure
  • Other commands:
Function Command
To check the version Puppet –version
File content manifest – site.pp file { ‘/tmp/dafile’:
content => “datextn”,
}
File content manifest – multiple nodes node ‘danodename’ {
file { ‘/tmp/dafile’:
content => “datextn”,
}
}
To remove packages package { ‘apache2.0-common’:
ensure => absent,
}
To update packages package { ‘puppet’:
ensure => latest,
}
To start service at the boot time service { ‘nginx’:
ensure => running,
enable => true, #false disables auto-startup
}
To set to a specific version package { ‘nginx’:
ensure => ‘1.1.18-1ubuntu0.1’,
}

Advantages of Puppet

  • Infrastructure as code(IAC): Puppet enables us to define IAC by easily coding a few scripts. It consists of version control, peer review, automated testing, and delivery.
  • Reduced downtime
  • Faster deployment time
  • Easy automation of repetitive tasks
  • Supports a lot of platforms like Windows, Debian, BSD, etc.

In this Puppet cheat sheet, we covered almost all Puppet topics that you should know to start working with it. If you want more, Intellipaat has resources that would satisfy your quest.

We at Intellipaat will never leave you disappointed as our approach is not just theoretical; the course we offer will provide you with step-by-step guidance and support to implement what you have learned about DevOps.

In the course, all the important DevOps concepts are included such as Docker, Chef, Git/GitHub, Ansible, Jenkins, Kubernetes, Selenium, Nagios, etc., along with Puppet. Sign up with us today and follow the right learning path toward DevOps!

We hope this tutorial helps you gain knowledge of DevOps course online. If you are looking to learn DevOps Training in a systematic manner with expert guidance and support then you can enroll to our DevOps course.

Course Schedule

Name Date Details
DevOps Certification 14 Dec 2024(Sat-Sun) Weekend Batch View Details
21 Dec 2024(Sat-Sun) Weekend Batch
28 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Technical Research Analyst - Big Data Engineering

Abhijit is a Technical Research Analyst specialising in Big Data and Azure Data Engineering. He has 4+ years of experience in the Big data domain and provides consultancy services to several Fortune 500 companies. His expertise includes breaking down highly technical concepts into easy-to-understand content.