O'Reilly logo

Puppet 3 Cookbook by John Arundel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. 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'], ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required