Creating Apache virtual hosts
Apache virtual hosts are an ideal place to use Puppet templates, because they generally consist of boilerplate code with just a few different bits of information for each site.
How to do it…
Here's a recipe to manage a simple virtual host:
Create the file
modules/apache/manifests/vhost.pp
with the following contents:# Manage an Apache virtual host define apache::vhost($domain='UNSET',$root='UNSET') { include apache if $domain == 'UNSET' { $vhost_domain = $name } else { $vhost_domain = $domain } if $root == 'UNSET' { $vhost_root = "/var/www/${name}" } else { $vhost_root = $root } file { "/etc/apache2/sites-available/${vhost_domain}.conf": content => template('apache/vhost.erb'), require => Package['apache2-mpm-prefork'], notify => Exec["enable-${vhost_domain}-vhost"], } exec { "enable-${vhost_domain}-vhost": command => "/usr/sbin/a2ensite ${vhost_domain}.conf", require => File["...