2

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.

Danijel Krmar
  • 129
  • 1
  • 1
  • 4
  • 2
    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

0 Answers0