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.erb
Testing key value pairs used in template
key is <%= @x %>
value is <%= @y %>
$
When I run this I create the 3 files in /tmp/test-[abc].out.
$ cat test-a.out
Testing key value pairs used in template
key is
value is
....
$ grep ^x test-*
$ grep ^y test-*
The values of x and y are not populated and do not show up in the dump of variables available to the template.
↧