Answering my own question, I think I've found the source of the problem. In the templatewrapper.rb file, there is a missing_method definition. The notes above this definition talk about having lookupvar fixing methods that are defined as "" to return :undefined. I though what if it is the same issue here with variables. When I changed this line in the template:

<% if has_variable?("server_admin") and server_admin != "undef" then %>

to this:

<% if has_variable?("server_admin") and server_admin.to_s != "undef" then %>

Then the templates started working as expected. It did NOT work when I did this:

<% if has_variable?("server_admin") and server_admin != "" then %>

So the comparison operator is slightly different after converting to a string.

- JimP

On Aug 20, 2009, at 12:27 PM, Jim Pirzyk wrote:

Hi,

I'm trying to generate apache virtual host configs and I have run into what I think is a bug. Here is my setup:

CentOS 5.3
puppet 0.24.8
puppetmaster 0.24.8

Here is my template for the vhost configuration:
-- vhost2.erb --
NameVirtualHost <%= name %>:<%= port %>

<VirtualHost <%= name %>:<%= port %>>
<% if has_variable?("server_admin") and server_admin != "undef" then %>
        ServerAdmin <%= server_admin %>
<% else %>
        ServerAdmin root@<%= name %>
<% end %>
        ServerName <%= name %>

        CustomLog /var/log/httpd/<%= name %>-access_log combined
        ErrorLog /var/log/httpd/<%= name %>-error_log

        DocumentRoot /var/www/html-<%= name %>

        <%= vhost_config %>
</VirtualHost>
-- end vhost2.erb --

Here is the define for calling the template:
-- apache.pp --
class apache {
define vhost2 ( $vhost_config, $port = 80, $server_admin = undef ) {
                file { "$name.conf":
                        name => $operatingsystem ? {
FreeBSD => "/usr/local/etc/apache22/ Includes/$name.conf",
                                Solaris => "/etc/apache/$name.conf",
default => "/etc/httpd/conf.d/ $name.conf",
                        },
                        ensure => present,
                        mode => 644,
                        content => template('vhost2.erb'),
                        notify => [ Service['httpd'], ],
                }
        }
...
}
-- end apache.pp --

and here is how I call it:

        apache::vhost2 { "repo.$domain":
                vhost_config => "
        <Directory \"/var/www/html-repo.$domain\">
                Options FollowSymLinks Indexes
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>",
        }

This is what I get:

-- repo.home.pirzyk.org.conf --
NameVirtualHost repo.home.pirzyk.org:80

<VirtualHost repo.home.pirzyk.org:80>

      ServerAdmin undef

      ServerName repo.home.pirzyk.org

CustomLog /var/log/httpd/repo.home.pirzyk.org-access_log combined
      ErrorLog /var/log/httpd/repo.home.pirzyk.org-error_log

      DocumentRoot /var/www/html-repo.home.pirzyk.org


      <Directory "/var/www/html-repo.home.pirzyk.org">
              Options FollowSymLinks Indexes
              AllowOverride None
              Order allow,deny
              Allow from all
      </Directory>
</VirtualHost>
-- end repo.home.pirzyk.org.conf --

If I set server_admin in the apache::vhost2 call, it does work correctly, just not if it is set to 'undef'

- JimP

--- @(#) $Id: dot.signature,v 1.15 2007/12/27 15:06:13 pirzyk Exp $
    __o  [email protected] -------------------------------------------
 _'\<,_
(*)/ (*) I'd rather be out biking.


--- @(#) $Id: dot.signature,v 1.15 2007/12/27 15:06:13 pirzyk Exp $
    __o  [email protected] -------------------------------------------
 _'\<,_
(*)/ (*) I'd rather be out biking.

Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to