Adding Classes Quick Start Guide

A newer version is available; see the version menu above for details.

Overview

Every module contains one or more classes. Classes are named chunks of Puppet code and are the primary means by which Puppet Enterprise configures nodes. The puppetlabs-apache module you installed in the Module Installation QSG contains a class called apache. In this exercise, you’ll use the apache class to launch the default Apache virtual host. You’ll create a group called apache_example and add the apache class to it.

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

Create the apache_example Group

  1. In the console, click Nodes > Classification.
  2. In the Node group name field, name your group apache_example.

    Note: Leave the Parent name and Environment values as their defaults (All Nodes and production, respectively).

  3. Click Add group.
  4. Click the apache_example group.
  5. From the Rules tab, in the Certname area, in the Node name field, enter the name of the PE-managed node you’d like to add to this group.
  6. Click Pin node.
  7. Click Commit 1 change.
  8. Repeat steps 5-7 for any other nodes you want to add.

    Tip: Adding nodes to groups by pinning individual nodes is referred to as adding nodes “statically.” In more complex deployments, beyond the scope of this QSG, you can add nodes “dynamically” by setting rules based on node facts.

Add the apache Class to the Example Group

Unless you have navigated elsewhere in the console, the apache_example node group should still be displayed in the Classification page.

To add the apache class to the example group:

  1. Click the Classes tab.

  2. In the Class name field, begin typing apache, and select it from the autocomplete list.

  3. Click Add class and then click Commit 1 change.

    The apache class now appears in the list of classes for your agent. You can see this list by clicking Nodes > Inventory and then clicking your node in the Inventory list. A page opens with your node’s details.

  4. From the command line on your agent, navigate to /var/www/html/, and create a file named index.html if it doesn’t already exist.

  5. Open index.html with the text editor of your choice and fill it with some content (for example, “Hello World”) or edit what is already there.

  6. From the command line of each PE-managed node, run puppet agent -t.

    This will configure the node using the newly assigned class. Wait one or two minutes.

  7. Open a browser and enter the IP address for the agent node, adding port 80 on the end, as in http://myagentnodeIP:80/.

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

Puppet Enterprise is now managing the default Apache vhost on your agent node. See the Apache ReadMe on the Forge to explore options for managing your Apache instances. The *Nix module writing QSG discusses how to write your own class that manages a web app running on an Apache virtual host.

Editing Class Parameters in the Console

You can use the console to modify the values of a class’s parameters without editing the module code directly.

To edit the parameters of the apache class:

  1. In the console, click Nodes > Classification.
  2. Click the apache_example group.
  3. Click the Classes tab, and find apache in the list of classes.

  4. From the Parameter Name drop-down list, choose the parameter you’d like to edit. For this example, we will use docroot.

    Note: The grey text that appears as values for some parameters is the default value, which can be either a literal value or a Puppet variable. You can restore this value by selecting Discard changes after you have added the parameter.

  5. In the Value field, enter /var/www.
  6. Click Add parameter.
  7. Click Commit 1 change.
  8. From the command line of each PE-managed node, run puppet agent -t.

    This will trigger a Puppet run to have Puppet Enterprise create the new configuration.

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.


Next: Quick Start: Classifying Nodes and Assigning User Permissions

↑ Back to top