Ask Your Question
0

Error: undefined local variable or method `vhost_name' for #<Puppet::Parser::TemplateWrapper

asked 2016-11-24 02:28:15 -0500

DurgaSudharshanam gravatar image

updated 2016-11-25 15:51:21 -0500

lupin gravatar image

i am trying to configure httpd in nodes using puppet.getting error in .erb file. Files are attached below. Can some one help to resolve this.

error

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Failed to parse template httpd/vhost_default.conf.erb:
  Filepath: /etc/puppetlabs/code/environments/test/modules/httpd/templates/vhost_default.conf.erb
  Line: 2
  Detail: undefined local variable or method `vhost_name' for #<Puppet::Parser::TemplateWrapper:0x4f940903>
 at /etc/puppetlabs/code/environments/test/modules/httpd/manifests/vhost.pp:14:17 at /etc/puppetlabs/code/environments/test/modules/httpd/manifests/init.pp:5 on node pnode.localdomain.com

Vhost.pp

define httpd::vhost (
  $port,
  $docroot,
  $servername = $title,
  $vhost_name = '*'
){
  include httpd

  file { "/etc/httpd/conf.d/vhost.conf" :
    ensure   => file,
    owner    => 'www',
    group    => 'www',
    mode     => '0644',
    content  => template('httpd/vhost_default.conf.erb'),
    require  => Package['httpd'],
    notify   => Service['httpd'],
    }
}

vhost_default.conf.erb

<% scope.lookupvar('httpd::vhost') %>
NameVirtualHost <%= vhost_name %>:<%= port %>
<VirtualHost <%= vhost_name %>:<%= port %>>
 ServerName <%= srvname %>
 ServerAdmin <%= serveradmin %>
 ServerAlias <%= serveralias %>
 DocumentRoot <%= docroot %>
 <Directory <%= docroot %>>
    Options <%= options %>
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
  ErrorLog <%= logroot %>/<%= name %>_error.log
  LogLevel warn
  CustomLog <%= logroot %>/<%= name %>_access.log combined
  ServerSignature Off
</VirtualHost>

init.pp

class httpd {
  include httpd::install
  include httpd::service

  httpd::vhost {'homepages':
  port    => 8081,
  docroot => '/var/www-testhost',
  }

}

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-11-25 16:04:40 -0500

lupin gravatar image

What do you intend to get out of this scope.lookupvar('httpd::vhost'). Parameters such as vhost_name can be reference within the template with @variable notation, i.e @vhost_name.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-11-24 02:28:15 -0500

Seen: 431 times

Last updated: Nov 25 '16