Creating Apache virtual hosts

Virtual hosts are a great application for ERB templates, because they generally use similar boilerplate code for every instance, with just one or two variables. Obviously, for certain sites or applications you will need specific options in the virtual host definition, and this template won't apply - but it should save you some trouble for simple sites.

How to do it…

  1. Add this to /etc/puppet/modules/apache/manifests/init.pp:
     define site( $sitedomain = "", $documentroot = "" ) { include apache if $sitedomain == "" { $vhost_domain = $name } else { $vhost_domain = $sitedomain } if $documentroot == "" { $vhost_root = "/var/www/${name}" } else { $vhost_root = $documentroot } file { "/etc/apache2/sites-available/${vhost_domain}.conf": ...

Get Puppet 2.7 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.