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, 2019 in Puppet by Andrew
1,252 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, 2019 by Sirajul
• 59,230 points

Related Questions In Puppet

0 votes
1 answer
0 votes
1 answer

Puppet: Error: Could not parse for environment production: Syntax error at '='; expected '}'

This error occurs if puppet apply -e is used ...READ MORE

answered Aug 1, 2019 in Puppet by Sirajul
• 59,230 points
4,455 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,503 views
+2 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, 2019 in Puppet by Sirajul
• 59,230 points
746 views
0 votes
1 answer

Error: Could not find declared class firewall at /etc/puppetlabs/code/environments/production/manifests/site.pp

The modules that you install on master need ...READ MORE

answered Aug 5, 2019 in Puppet by Sirajul
• 59,230 points
1,845 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP