Hey Josh,

Don't use the $ for variables in Templates - Puppet variables and arrays
are accessed as local variables/arrays in templates.  So try this:  TEST:
<%= myhash[key][subkey1] %>


On Wed, Apr 11, 2012 at 9:04 AM, Josh <j...@chickenmonkey.co.uk> wrote:

> I am using puppet version 6.2 (the one that comes with squeeze) in case it
> makes a difference.
>
> I am new to puppet and am having a problem getting access to the elements
> of a hash in my erb templates and no matter what I google for I cannot seem
> to find out what I am doing wrong.
>
> I have stripped everything back to example code to rule out other things,
> in reality I have split my files up a but to avoid the monolithic init.pp
> and nodes.pp. Anyway...
>
> my nodes.pp has this in it:
>
> node 'pc01.domain.com' {
>
>   # Test code
>   $myhash = {
>     key => {
>       subkey1 => 'foo',
>       subkey2 => 'bar'
>     }
>   }
>
>   include mymodule
> }
>
> Then in the modules init.pp I have:
>
> class mymodule {
>   # Test code
>   notice($myhash[key][subkey1])
>   notice($myhash[key][subkey2])
>   file { "/tmp/test":
>     ensure => present,
>     content => template("mymodule/test.erb"),
>   }
> }
>
> If I run puppet against this the two notice lines work fine so I have
> access to the data within the module, the problem is getting it into the
> template. I tried a few different syntaxes to no effect:
>
> So first I tried a template like so:
> TEST: <%= $myhash[key][subkey1] %>
>
> This gave me the error:
> *err: Could not retrieve catalog from remote server: Error 400 on SERVER:
> Failed to parse template mymodule/test.erb: Could not find value for 'key'
> at /etc/puppet/modules/mymodule/manifests/init.pp:7 on node
> pc01.domain.com*
>
> If I quote the string in the template (i.e. "<%= $myhash[key][subkey1] %>")
> then it just spits out that string into the file rather than interpreting
> the data.
>
> I have similar errors if I try to use scope.lookupvar to explicitly
> specify where things are too.
>
> So, what am I doing wrong or is it just not possible to pick a single hash
> element and put it into a template.
>
> Thanks
> Josh
> p.s. my Ruby sucks so if I have to go down that route it'll need to be a
> noddy explanation
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/nSPGiquUVBIJ.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>



-- 

Gary Larizza
Professional Services Engineer
Puppet Labs

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to