On Monday, June 23, 2014 7:29:59 AM UTC-5, Rob Shand wrote:
>
> Hi All,
>
> So this was working on a Puppet Enterprise 3.2 puppet master but when 
> testing on a 3.4 Puppet Master I'm getting the following failure 'undefined 
> method `[]' for nil:NilClass' . So I know that this is telling me it's 
> failed to retrieve a value, but I'm wondering why I might be failing to 
> retrieve the value from the nested hash for 'locations' and 'terminals' 
> when it was previously working on puppet 3.2.
>
>

I'm inclined to suspect that either it wasn't quite the same thing that 
worked on PE 3.2 (considering both manifests and data), or that it didn't 
work as well as you thought.

Alternatively, is the Puppet version the only thing that changed?  For 
example, are you running on the same version of Ruby?

 

> Does anyone have any clues on why this is failing when previously it was 
> working on an earlier release . . .? thanks in advance.
>
> $ sudo /usr/local/bin/puppet apply --modulepath 
> /opt/puppet/share/puppet/modules:/etc/puppetlabs/puppet/modules 
> ./puppet-modules/digital/tests/init.pp 
> --environment uat --noop
>
> This file (./puppet-modules/digital/tests/init.pp) is literally just a 
> single line containing an include on the class include 'digital' 
>  
> Error: Failed to parse template digital/adapter-config.json.erb:
>   Filepath: 
> /etc/puppetlabs/puppet/modules/digital/templates/adapter-config.json.erb
>   Line: 6
>   Detail: undefined method `[]' for nil:NilClass
>  at /etc/puppetlabs/puppet/modules/digital/manifests/app.pp:41 on node 
> localhost
> Error: Failed to parse template digital/adapter-config.json.erb:
>   Filepath: 
> /etc/puppetlabs/puppet/modules/digital/templates/adapter-config.json.erb
>   Line: 6
>   Detail: undefined method `[]' for nil:NilClass
>  at /etc/puppetlabs/puppet/modules/digital/manifests/app.pp:41 on node 
> localhost
> [ERROR] - Running puppet-modules/digital/tests/init.pp
>
> Hiera Data :- From a hiera lookup test here's the data structure I'm 
> using (simplified for the purposes of this thread)
>


And you can reproduce your error with that simplified data?  Otherwise it's 
useless for us to examine it.

 

>
> $ hiera -d -c /etc/puppetlabs/puppet/hiera.yaml hash_data 
> calling_module=digital
>
> {"ABC"=> 
>   {"name"=>"test01", "port"=>"20000", "host"=> 
>     {"foo01"=> {"locations"=>"0001", "terminals"=>"1,2,3,4"}, 
>      "foo02"=>{"locations"=>"0002", "terminals"=>"1,2,3,4"}}}, 
> "DEF"=> {"name"=>"test02", "port"=>"20000", "host"=> 
>    {"foo01"=>{"locations"=>"0002", "terminals"=>"5,6,7,8"}, 
>     "foo02"=>{"locations"=>"0001", "terminals"=>"5,6,7,8"}}}}
>
> ERB - Template File (json output file, hence the 'hash_data.size' at the 
> end to prevent a trailing ',' in order to preserve syntax)
>
> {
>   "wager_hosts":[<% @hash_data.each_with_index do |(key, hash) ,i| -%>{
>


I don't like "hash" as a variable name, as it seems both uninformative and 
needlessly risky of conflicting with a keyword or function name (though I 
am not aware of any actual conflict).

 

>     "domain":"<%= key -%>",
>     "name":"<%= hash['name'] -%>",
>     "port":<%= hash['port'] -%>,
>     "locations":[<%= hash['host']['foo01']['locations'] -%>],
>     "terminals":[<%= hash['host']['foo01']['terminals'] -%>]
>     }<%= ',' if i < (@hash_data.size - 1) %><%end-%>
>   ]
> }
>
>

My comment above notwithstanding, I don't see anything clearly wrong with 
your template.  That leaves me suspicious of your data, but I don't think 
the template you present would break when the value of @hash_data is what 
you present.

If it is really true that exactly the same code, template, and manifests 
work under PE 3.2, but fail under PE 3.4, then the most likely locus of the 
problem is the part you didn't show us: the manifests.  The most relevant 
is the one containing the template() call that causes the given template to 
be evaluated.


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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/40a2f3f4-f331-44ad-8f1e-ef18835eb9db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to