I am new to puppet and am trying to figure out variable scoping. I have a 
test module that I am using for this and it looks like this:

manifiests/init.pp:

class test {
  include test::params

  file { 'testfile' :
    path   => "/tmp/testfile",
    content => template("test/testfile.erb"),
  }
}

manifests/params.pp:

class test::params {
  $p1 = hiera('param1')
  $p2 = hiera('param2')
}

templates/testfile.erb:

this is the first parameter:  <%= @p1 %>
this is the second parameter:  <%= @p2 %>

global.yaml:

---
  param1: "this is the first one"
  param2: "this is the second one"

Based on what I am seeing in the ProPuppet book (the discussion of the 
puppet module in Chap. 2, pp69-70), this should work. However, the values 
are not being inserted in the template. In order to get them in, I have to 
add something like this to the init.pp manifest:

  $a = $::test::params::p1
  $b = $::test::params::p2

and reference @a and @b in the template.

So the question is: Am I missing something or is there an error in the 
ProPuppet example?

If I need to add the $a = …. and $b=… lines to the init.pp, what, if any is 
the advantage to having a params.pp manifest. I could just put the hiera() 
calls in init.pp.

thanks for your patience.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/abcf9bb6-b3a2-483d-8655-3b6a6eed8196%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to