err: Failed to parse template base/puppet.conf.erb: Could not find value for 'puppetserver' at /etc/puppet/modules/base/manifests/config.pp:13 on node ...

0 votes

I'm new to puppet templates and in an attempt to create one using resources that are available online.Here's a miniscule part of the template located at base/templates/puppet.conf.erb

...
server=<% puppetserver %>

I'm getting the above mentioned error while using this template.

Apart from other necessary stuff there's a module named "base" at

/etc/puppet/modules/base/
    ./manifests
    ./manifests/service.pp
    ./manifests/init.pp
    ./manifests/params.pp
    ./manifests/config.pp
    ./manifests/install.pp
    ./templates
    ./templates/puppet.conf.erb

base/manifests/init.pp:

class base {
  include base::install, base::service, base::config, base::params
}

base/manifests/config.pp

class base::config {
  include base::params
  File {
    require => Class["base::install"],
    ensure => present,
    owner => root,
    group => root,
  }
  file { "/etc/puppet/puppet.conf":
    mode => 0644,
    content => template("base/puppet.conf.erb"),
    require => Class["base::install"],
    nofity => Service["puppet"],
  }

base/manifests/params.pp

class base::params {
  $puppetserver = "pup01.sdirect.lab"
}

I'm having a tough time identifying where exactly am i going wrong? Any idea where my $puppetserver should be defined?

Aug 9 in Puppet by Andrew
30 views

1 answer to this question.

0 votes

For puppet to find the value of the template the name of the "puppetserver" should be completely qualified if defined in a different scope.

Since it is defined in base::params , it can be referred to simply as "puppetserver" in that scope but while evaluating the template from within base::config, you're in a different scope and so you can't refer to the variable simply by its short name. Although "include" adds the other class to the catalog, but the rules still remain the same.

And in order to access it you need to address it using the fully qualified class name: base::params::puppetserver. Within the manifest it would be $base::params::puppetserver. 

This process is slightly different while accessing the variable within the template,You need to use scope.lookupvar("base::params::puppetserver")

Your template should look something like this:

...
server=<%= scope.lookupvar("base::params::puppetserver") %>
answered Aug 9 by Sirajul
• 25,420 points

Related Questions In Puppet

0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
147 views
0 votes
1 answer
0 votes
1 answer

Error: Could not find class git::config for xxxx on node xxxx

You should note that you cannot call include on git::config. git::config is a ...READ MORE

answered Jul 31 in Puppet by Sirajul
• 25,420 points
52 views
0 votes
1 answer