On Friday, July 12, 2013 7:48:36 AM UTC-5, Ivailo Tanusheff
wrote:>
> Hi,
>
> I have stupid situation that I may workaround but I think there is an
> elegant way to deal with.
> Still I need the community help.
>
> In some class X I have:
> $control = {
> dev => {
> id => 7,
> name => ''GG''
> },
> prod => {
> id => 1,
> name => ''Info''
> }
> }
>
> In some other class, which I apply to a node I have defined file from a
> templete, where I want to use those values depending on the zone property.
>
> <%
> $zone = scope.lookupvar(''y::_zone'')
> $c_data = scope.lookupvar(''x::control[${zone}]'')
> -%>
>
> The zone property is OK and equals to dev.
> I can''t access the $c_data as in looks like nil (undefined).
> And I need to output something as:
>
> ID=<%= $c_data[''id''] %>
>
> which fails with error Detail: undefined method `[]'' for
nil:NilClass
>
> Can you give me a hint/help?
>
You must ensure that class X has been declared before the template that
references its variables is evaluated. Supposing that class X is nowhere
declared via the parameterized-style syntax, you might accomplish that like
so:
class z {
include ''x''
include ''y''
$result = template(''my_template.tmpl'')
}
John
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.