$title and $name returns node name

20 views
Skip to first unread message

Ugo Bellavance

unread,
Oct 1, 2015, 10:27:18 AM10/1/15
to Puppet Users
Hi,

I adapted the apache module for my needs and use it to create vhosts.

Declaration example:

  apache::vhost { 'cust1-user1app1' :
    client         => 'cust1,
    envstage           => 'dev',
    application           => 'app1',
    devuser            => 'user1',
    vhost_name     => "${name}",
  }

$name and $title are shown as being cust1-user1app1 in the logs (notice directive), but when it creates the file from the template, the result of <%= vhost_name %> is the node name. Example:

node 'webserver1' inherits webserverbase

Excerpt from puppet --noop:

+<VirtualHost webserver1:80>

Puppet version: puppet-2.7.26-2.el6 (EPEL)


As a side note, is there a way to automatically generate the name of the declaration (cust1-user1app1 based on the variables?

Thanks,

Ugo

Gabriel Filion

unread,
Oct 1, 2015, 11:47:10 AM10/1/15
to puppet...@googlegroups.com
Hey there,

On 01/10/15 10:27 AM, Ugo Bellavance wrote:
> I adapted the apache module for my needs and use it to create vhosts.
>
> Declaration example:
>
> apache::vhost { 'cust1-user1app1' :
> client => 'cust1,
> envstage => 'dev',
> application => 'app1',
> devuser => 'user1',
> vhost_name => "${name}",
> }

$name and $title have different values depending on the context in which
they are used.

in the declaration above, you are not within the context of
apache::vhost, but rather in the context surrounding it (maybe the node?
hence why $name would be the host name?)

$name will have the value that you would expect it to have if you were
in the "define". e.g.:

define apache::vhost ( $client, $envstage, $application, $devuser,
$vhost_name) {

notify { "${name} here will have the name of the resource, so in your
case it should be 'cust1-user1app1'": }

}


If you want to have the same value as the resource name be given to a
parameter you need to repeat that value. So you can use a variable like so:

$new_vhost = 'cust1-user1app1'
apache::vhost { $new_vhost:
# ...
vhost_name => $new_vhost,
}

--
Gabriel Filion

signature.asc
Reply all
Reply to author
Forward
0 new messages