Show Table of Contents
2.4. Installing a HTTP Server
Our Puppet module will install the packages necessary to run a HTTP server. This requires a resource definition that defines configurations for the
httpd package.
In the module's
manifests directory, create a new manifest file called httpd.pp:
# touch mymodule/manifests/httpd.pp
This manifest will contain all HTTP configuration for our module. For organizational purposes, we will keep this manifest separate from the
init.pp manifest.
Add the following content to the new
httpd.pp manifest:
class mymodule::httpd {
package { 'httpd':
ensure => installed,
}
}
This code defines a subclass of
mymodule called httpd, then defines a package resource declaration for the httpd package. The ensure => installed attribute tells Puppet to check if the package is installed. If it is not installed, Puppet executes yum to install it.
We also need to include this subclass in our main manifest file. Edit the
init.pp manifest:
class mymodule {
include mymodule::httpd
}
It is now time to test the module. Run the following command:
# puppet apply mymodule/tests/init.pp --noop
The
puppet apply command applies the configuration in the manifest to your system. We use the test init.pp manifest, which refers to the main init.pp manifest. The --noop performs a dry-run of the configuration, which shows only the output but does not actually apply the configuration. The output should resemble the following:
Notice: Compiled catalog for puppet.example.com in environment production in 0.59 seconds
Notice: /Stage[main]/Mymodule::Httpd/Package[httpd]/ensure: current_value absent, should be present (noop)
Notice: Class[Mymodule::Httpd]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.67 seconds
The highlighted line is the result of the
ensure => installed attribute. The current_value absent means that Puppet has detected the httpd package is not installed. Without the --noop option, Puppet would install the httpd package.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.