Puppet Tutorial - One Stop Solution For Configuration Management

Saurabh Kulshrestha
Edureka
Published in
8 min readNov 18, 2016
Puppet Tutorial - Edureka

Puppet is a Configuration Management tool that is used for deploying, configuring, and managing servers. In this Puppet Tutorial following topics will be covered:

  • What is Configuration Management?
  • Puppet Architecture
  • Puppet Master-Slave Communication
  • Puppet Components
  • Hands-On

What is Configuration Management?

In this Puppet Tutorial, I will explain you about different interdependent activities of Configuration Management. But before that, let us understand what is Configuration Item (CI). A Configuration Item is any service component, infrastructure element, or other items that needs to be managed in order to ensure the successful delivery of services. Examples of CI include individual requirements documents, software, models, and plans.

Configuration Management consists of the following elements:

  • Configuration Identification
  • Change Management
  • Configuration Status Accounting
  • Configuration Audits

The diagram below explains these components:

Components of Configuration Management- Puppet Tutorial

Configuration Identification: It is the process of:

  • Labeling software and hardware configuration items with unique identifiers
  • Identifying the documentation that describes a configuration item
  • Grouping related configuration items into baselines
  • Labeling revisions to configuration items and baselines.

Change Management: It is a systematic approach to dealing with change both from the perspective of an organization and the individual.

Configuration Status Accounting: It includes the process of recording and reporting configuration item descriptions (e.g., hardware, software, firmware, etc.) and all departures from the baseline during design and production. In the event of suspected problems, the verification of baseline configuration and approved modifications can be quickly determined.

Configuration Audits: Configuration audits provide a mechanism for determining the degree to which the current state of the system is consistent with the latest baseline and documentation. Basically, it is a formal review to verify that the product being delivered will work as advertised, promoted or in any way promised to the customers. It uses the information available as an outcome of the quality audits and testing along with the configuration status accounting information, to provide assurance that what was required has been build.

Let us understand Configuration Management with a use-case. Suppose if you have to update a particular software or you want to replace it, In that case, the below flowchart should be followed for successful Configuration Management:

Flowchart for Configuration Management- Puppet Tutorial

Now is the correct time to understand Puppet Architecture.

Architecture of Puppet

Puppet uses a Master-Slave architecture. The diagram below depicts the same:

Puppet Architecture - Puppet Tutorial

The following functions are performed in the above image:

  • The Puppet Agent sends the Facts to the Puppet Master. Facts are basically key/value data pair that represents some aspect of the Slave state, such as its IP address, uptime, operating system, or whether it’s a virtual machine. I will explain Facts in detail later in the blog.
  • Puppet Master uses the facts to compile a Catalog that defines how the Slave should be configured. A catalog is a document that describes the desired state for each resource that the Puppet Master manages on a Slave. I will explain catalogs and resources in detail later.
  • Puppet Slave reports back to Master indicating that Configuration is complete, which is visible in the Puppet dashboard.

Puppet Master-Slave Communication

Puppet Master and Slave communicate through a secure encrypted channel with the help of SSL. The diagram below depicts the same:

Communication Between Puppet Slave & Master - Puppet Tutorial

As you can see from the above Image:

  • Puppet Slave asks for Puppet Master certificate.
  • After receiving Puppet Master certificate, Master requests for Slave certificate.
  • Once Master has signed the Slave certificate, Slave requests for configuration/data.
  • Finally, Puppet Master will send the configuration to Puppet Slave.

Let us now have a look at various Puppet components.

Components of Puppet

Manifests: Every Slave has got its configuration details in Puppet Master, written in the native Puppet language. These details are written in the language which Puppet can understand and are termed as Manifests. They are composed of Puppet code and their filenames use the .pp extension. These are basically Puppet programs.
For example, You can write a Manifest in Puppet Master that creates a file and installs Apache server on all Puppet Slaves connected to the Puppet Master.

Module: A Puppet Module is a collection of Manifests and data (such as facts, files, and templates), and they have a specific directory structure. Modules are useful for organizing your Puppet code because they allow you to split your code into multiple Manifests. Modules are self-contained bundles of code and data.

Resource: Resources are the fundamental unit for modeling system configurations. Each Resource describes some aspect of a system, like a specific service or package.

Facter: Facter gathers basic information (facts) about Puppet Slave such as hardware details, network settings, OS type and version, IP addresses, MAC addresses, SSH keys, and more. These facts are then made available in Puppet Master’s Manifests as variables.

Mcollective: It is a framework that allows several jobs to be executed in parallel on multiple Slaves. It performs various functions like:

  • Interact with clusters of Slaves, whether in small groups or very large deployments.
  • Use a broadcast paradigm to distribute requests. All Slaves receive all requests at the same time, requests have filters attached, and only Slaves matching the filter will act on requests.
  • Use simple command-line tools to call remote Slaves.
  • Write custom reports about your infrastructure.

Catalogs: A Catalog describes the desired state of each managed resource on a Slave. It is a compilation of all the resources that the Puppet Master applies to a given Slave, as well as the relationships between those resources. Catalogs are compiled by a Puppet Master from Manifests and Slave-provided data (such as facts, certificates, and an environment if one is provided), as well as an optional external data (such as data from an external Slave classifier, exported resources, and functions). The Master then serves the compiled Catalog to the Slave when requested.

Now in this Puppet Tutorial, my next section will focus on Hands-On.

Hands-On

I will show you how to deploy MySQL and PHP from Puppet Master to Puppet Slave. I am using only one Slave for demonstration purpose there can be hundreds of Slaves connected to one Master. To deploy PHP and MySQL I will use predefined modules available at forge.puppet.com. You can create your own modules as well.

Step 1: In Puppet Master install MySQL and PHP modules.

Execute this:

puppet module install puppetlabs-mysql –version 3.10.0

This MySQL module installs, configures, and manages the MySQL service. This module manages both the installation and configuration of MySQL, as well as extending Puppet to allow management of MySQL resources, such as databases, users, and grants.

puppet module install mayflower-php –version 4.0.0-beta1

This module is used for managing PHP, in particular, php-fpm. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

Step 2: In Puppet Manifests include MySQL server and PHP.

Execute this:

vi /etc/puppet/manifests/site.pp

You can use any other editor as well like vim, gedit etc. In this site.pp file add the following:

include '::mysql::server' 
include '::php'

Save and quit.

Step 3: Puppet Slaves pulls its configuration from the Master periodically (after every 30 minutes). It will evaluate the main manifest and apply the module that specifies MySQL and PHP setup. If you want to try it out immediately, you need to run the following command on every Slave node:

Execute this:

puppet agent -t

So MySQL and PHP are installed successfully on the Slave node.

Step 4: To check the version of MySQL and PHP installed:

Execute this:

mysql -v
php -version

Congratulations! MySQL and PHP are up and running in your Puppet Slave. Here I have shown you only one Slave but imagine if there are hundreds of Slaves. In that scenario your work becomes so easy, Just specify the configurations in Puppet Master and Puppet Slaves will automatically evaluate the main manifest and apply the module that specifies MySQL and PHP setup.

So that brings an end to this blog on Puppet Tutorial.If you wish to check out more articles on the market’s most trending technologies like Artificial Intelligence, Python, Ethical Hacking, then you can refer to Edureka’s official site.

Do look out for other articles in this series which will explain the various other aspects of DevOps.

1. DevOps Tutorial

2. Git Tutorial

3. Jenkins Tutorial

4. Docker Tutorial

5. Ansible Tutorial

6. Chef Tutorial

7. Nagios Tutorial

8. How To Orchestrate DevOps Tools?

9. Continuous Delivery

10. Continuous Integration

11. Continuous Deployment

12. Continuous Delivery vs Continuous Deployment

13. CI CD Pipeline

14. Docker Compose

15. Docker Swarm

16. Docker Networking

17. Ansible Roles

18. Ansible Vault

19. Ansible for AWS

20. Jenkins Pipeline

21. Top Git Commands

22. Top Docker Commands

23. Git vs GitHub

24. DevOps Interview Questions

25. Who Is A DevOps Engineer?

26. DevOps Life cycle

27. Git Reflog

28. Ansible Provisioning

29. Top DevOps Skills That Organizations Are Looking For

30.Waterfall vs Agile

31. Maven For Building Java Applications

32. Jenkins CheatSheet

33. Ansible Cheat Sheet

34. Ansible Interview Questions And Answers

35. 50 Docker Interview Questions

36. Agile Methodology

37. Jenkins Interview Questions

38. Git Interview Questions

39. Docker Architecture

40. Linux commands Used In DevOps

41. Jenkins vs Bamboo

42. Nagios Interview Questions

43.DevOps Real-Time Scenarios

44.Difference between Jenkins and Jenkins X

45.Docker for Windows

46.Git vs Github

Originally published at www.edureka.co on December 7, 2016.

--

--

Saurabh Kulshrestha
Edureka

Saurabh is a technology enthusiast with interest in DevOps, Artificial Intelligence, Big Data and Data Science.