Puppet cannot find variable for template

Just starting with Puppet and I'm having problems with my first template. It should be very simple, but I can’t understand.

I have a "base" module in

/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

There are other things, but it is not necessary.

base / manifest / 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 / manifest / params.pp

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

Finally, the interesting part of the template in the /templates/puppet.conf.erb database

...
server=<% puppetserver %>

Error message:

err: Failed to parse the template database /puppet.conf.erb: Failed to find the value for 'puppetserver' in /etc/puppet/modules/base/manifests/config.pp:13 in node ...

I do not understand what the problem is. I copied this part directly from the Pro Puppet book.

Can someone show me where $ puppetserver should be defined and how?

+3
source share
3

, "puppetserver" , Puppet , , .

base::params, "puppetserver" . base::config, . "Include" , .

, : base::params::puppetserver. , $base::params::puppetserver. Pro Puppet ssh::config ssh::service, "ssh_service_name" params ( 43-45).

, , scope.lookupvar("base::params::puppetserver"). ( ) :

...
server=<%= scope.lookupvar("base::params::puppetserver") %>

Scope and Puppet 2.7.

(Edit: , .)

+14

№1 , .

, :

class base::config {
  include base::params
  $puppetserver = $base::params::puppetserver
  ...
}

, :

server=<% puppetserver %>
+6

You can also use inheritance:

class puppet::config inherits puppet::params {
....

This way you do not need to define again $puppetserverin this class.

+1
source

All Articles