Quick start » Adding classes (*nix)

This version is out of date. For current versions, see Puppet packages and versions.


Every module contains one or more classes. Classes are named chunks of Puppet code and are the primary means by which Puppet configures nodes. The puppetlabs-apache module you installed in the Module Installation Quick Start Guide contains a class called apache. In this example, you will:

Prerequisites: This guide assumes you’ve already installed Puppet, and have installed at least one *nix agent and the puppetlabs-apache module.

Before starting this walk-through, complete the previous exercises in the introductory quick start guide. You should still be logged in as root or administrator on your nodes.

Add Apache to the main manifest

  1. From the command line of your Puppet master, navigate to the main manifest directory: cd /etc/puppetlabs/code/environments/production/manifests.
  2. Use your text editor to open the site.pp file, and edit it so that it contains the following Puppet code:

     node default {
       include apache

    Note: If you have already created the default node class, simply add include apache to it. Code from the Hello World! exercise does not need to be removed, but a class cannot be declared twice. We will explore this later in the guide.

  3. Ensure that there are no errors in the Puppet code by running puppet parser validate site.pp on the command line of your Puppet master. The parser will return nothing if there are no errors. If it does detect a syntax error, open the file and fix the problem before continuing.
  4. From the command line of your Puppet agent, run puppet agent -t to trigger a Puppet run.

Create the index.html file

  1. On the Puppet agent, navigate to /var/www/html, and create a file called index.html if it does not already exist.
  2. Open index.html in your text editor and fill it with some content (for example, “Hello World”) or edit what is already there.
  3. From the command line of your Puppet agent, run puppet agent -t.
  4. Open a web browser and enter the IP address for the Puppet agent, adding port 80 on the end, as in http://myagentnodeIP:80/.

    You will see the contents of /var/www/html/index.html displayed.

Editing class parameters in the main manifest

You can edit the parameters of a class in site.pp as well. Parameters allow a class to request external data. If a class needs to configure itself with data other than Puppet facts, provide that data to the class via a parameter.

To edit the parameters of the apache class:

  1. From the command line of your Puppet master, navigate to /etc/puppetlabs/code/environments/production/manifests.
  2. Use your text editor to open site.pp.
  3. Replace the include apache command with the following Puppet code:

     class { 'apache':
     	  docroot => '/var/www'

    Note: You must remove include apache because Puppet will only allow you to declare a class once.

That’s it! You have set the Apache web server’s root directory to /var/www instead of its default /var/www/html. If you refresh http://myagentnodeIP:80/ in your web browser, it shows the list of files in /var/www. If you click html, the browser will again show the contents of /var/www/html/index.html.

Note: If you have Puppet Enterprise, you can do the steps in this guide through the PE web UI, the console.

Next: Quick Start: Writing Modules

See an issue? Please file a JIRA ticket in our [DOCUMENTATION] project
Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.