0

I'm trying to configure a few Apache virtual hosts with the puppetlabs/apache module. My issue is with the ${name} variable. I expected DocumentRoot to be set to /var/www/atoms.one, but instead it is set to /var/www/main.

What am I doing wrong?

My manifest:

class { apache: }

apache::vhost { 'atoms.one':
    port          => '80',
    serveraliases => [ "*.${name}" ],
    docroot       => "/var/www/${name}",
    directories   => [
        { path => "/var/www/${name}", },
    ],
}
stephenwade
  • 1,057
  • 2
  • 20
  • 37

1 Answers1

1

Inside a defined type's body, the special variable $name represents the name / title of the defined type instance. But you have not presented a defined-type body -- rather, you have presented a declaration of a defined-type instance, and one that appears at top scope, at that. The declaration does not create a scope for $name to mean anything different within than it does without.

I'm having trouble finding documentation for the meaning of $name outside the scope of a defined-type body, but I know from experience that inside a class it represents the class name. I suppose you are seeing the name of the top scope, for which "main" is a plausible value.

The bottom line is that $name does not provide the kind of shortcut you are trying to use it for. You could instead create a defined type wrapper of your own around apache::vhost, and do the shortcutting there. Alternatively, you could create your own variable to use instead of $name.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157