Installing and configuring Apache2 with Puppet module
Categories:
[school]
Tags:
[linux],
[puppet],
[linux-centralized-management-course],
[apache],
[debian]
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":}'
After that I tested with my browser if Apache was installed and started:
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:
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'],
}
Finally, I applied the module modifications:
sudo puppet apply --modulepath modules/ -e 'class {"install-apache":}'
Modifications has been successfully applied, now to see that the port has changed:
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
- Learning Puppet – Resource Ordering / Package-File-Service (http://docs.puppetlabs.com/learning/ordering.html#packagefileservice)
- Tero Karvinen: Linux Centralized Management lecture 2 (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linuxin-keskitetty-hallinta-%E2%80%93-ict4tn011-4-syksylla-2013)