Ask Your Question
0

puppet variables not coming through in template?

asked 2013-10-04 09:42:26 -0500

lorcutt gravatar image

updated 2013-10-04 10:33:39 -0500

GregLarkin gravatar image

Here is a simple test case that shows what I am trying to do. I have a hash passed in through hiera and I want to apply a different template to generate a different file for each key. However the key/value pairs I split out in the puppet code do not seem to be available in the template.

Is this a bug or am I doing something wrong?

$ cat init.pp
class test
{
  $test = { a=>1,b=>2,c=>3 }

  $test.each |$x, $y|
  {
    file { "/tmp/test-$x.out":
      ensure => file,
      content => template("test/test-$x.erb")
    }
  }
}
$

$ cat test-a ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-10-04 10:47:36 -0500

GregLarkin gravatar image

This bug is reported here ( http://projects.puppetlabs.com/issues/21508 ), and should be fixed in 3.3.0. If you are running an earlier version, you can work around it by changing your template like so:

Testing key value pairs used in template
key is <%= scope.lookupvar('x') %>
value is <%= scope.lookupvar('y') %>
edit flag offensive delete link more

Comments

Thanks - I thought I had tried that. Fixed this test case, so I'll go try it on my real case. I'm running 3.2.2. I'll have ...(more)

lorcutt gravatar imagelorcutt ( 2013-10-04 11:22:15 -0500 )edit

Glad it helped, and please mark my answer as correct when you have a moment - thank you!

GregLarkin gravatar imageGregLarkin ( 2013-10-04 12:15:51 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-10-04 09:42:26 -0500

Seen: 145 times

Last updated: Oct 04 '13