Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi there puppeters :),

I hope you can help me with a situation. Namely, I will use puppet to deploy many (I mean really many) nodes with Apache installed. The problem I have is that for now the only way to create a vhost with a specified ServerName is to issue the server name in the main puppetmaster file (site.pp). It looks something like this:

    case $::hostname {
            hostname1: {vhost_default { 'hostname1.domain': }}
            hostname2: {vhost_default { 'hostname2.domain': }}

Is there a way of creating a vhost file without having to issue the name. Meaning, that the puppetmaster reads the hostname and writes it by itself into the template. The template looks as follows (only the important part):

<VirtualHost *:80>
    ServerName <%= fqdn %>
    ServerAlias www.<%= fqdn %>

And the init.pp for apache with the template portion: define vhost_default() {

file { "/etc/apache2/sites-available/domain.conf":
    owner   => 'root',
    group   => 'root',
    mode    => 644,
    content => template( 'apache/default_vhost.erb' ),
    require => [ Package[ 'apache2' ] ]

Or can you maybe think of another way of deploying apache vhost files? (Maybe without ServerName directive?) Thanks in advance.

share|improve this question
Try vhost_default { $fqdn: } if name of vhost is always equal to full hostname. You can also use extlookup() or generate() to get names if they are different from $fqdn. – kupson Feb 28 '12 at 13:05
Thx, I created the file in the define statement. The solution was to simply move the file creation into the class. Now it puts fqdn by itself. – Danijel Krmar Mar 12 '12 at 10:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.