Welcome fellow earthling!

You have landed on my notebook, where I keep my notes.

Installing and configuring Apache2 with Puppet module

I made a module to Puppet that installs and configures Apache2 package. I changed the default listening port for Apache from port 80 to port 8080 using the a template from a config file.

Installing and starting Apache with a Puppet module

First I created the usual module directory structure:

mkdir -p install-apache/manifests
nano install-apache/manifests/init.pp

I wrote the following in the init-file:

class install-apache {
    package {'apache2':
        ensure => 'present',
    }

    service {'apache2':
        enable => 'true',
        ensure => 'running',
    }
}

The following code checks that apache2 is installed, and if it is not, it will install it. It will also check that Apache is running. Next I applied the new module with the following command:

sudo puppet apply --modulepath modules/ -e 'class {"install-apache":}'

install-apache-1

After that I tested with my browser if Apache was installed and started:

apache2-installed1

Adding a modified config file

First create a templates-directory to module root:

mkdir install-apache/templates
cp /etc/apache2/ports.conf modules/install-apache/templates/ports.conf.erb

I edited the template so that the default port for Apache would be 8080 instead of normal 80:

apache-port-config

Then I edited the init.pp manifest file so that it would update the config file with new modifications to update the config file:

file {'/etc/apache2/ports.conf':
   content => template('install-apache/ports.conf.erb'),
   notify => Service['apache2'],
}

apache-config-edit

Finally, I applied the module modifications:

sudo puppet apply --modulepath modules/ -e 'class {"install-apache":}'

module-apache-applied

Modifications has been successfully applied, now to see that the port has changed:

apache-port-changed1

apache-port-changed2

In the first picture I tried to use the normal 80 port, where Apache is not listening anymore. When I tried on port 8080, Apache responds me a directory listing, so the module config template works!

Sources

Next Post Previous Post