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.
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)
$ 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| -%>{
"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-%>
]
}
Version info:
$ puppet --version
3.4.3 (Puppet Enterprise 3.2.3)
$ /opt/puppet/bin/ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
Server is a CentOS 6.5 box
PS - I've manually run a simplified piece of ruby code and works fine to retrieve the values when I assign the data structure, so what's going on ?
$ cat test.erb
#!/opt/pupppet/bin/ruby
#
require 'erb'
data={"NSW"=> {"name"=>"test01", "port"=>"20000", "host"=> {"foo01"=>{"locations"=>"0001", "terminals"=>"1,2,3,4"}, "foo02"=>{"locations"=>"0002", "terminals"=>"1,2,3,4"}}}, "VIC"=> {"name"=>"test02", "port"=>"20000", "host"=> {"foo01"=>{"locations"=>"0002", "terminals"=>"5,6,7,8"}, "foo02"=>{"locations"=>"0001", "terminals"=>"5,6,7,8"}}}}
data.each_with_index do |(key, hash) ,i|
p hash['name']
p hash['port']
p hash['host']['foo01']['locations']
p hash['host']['foo01']['terminals']
end
[vagrant@vagrant-centos65 ~]$ /opt/puppet/bin/ruby test.erb
"test01"
"20000"
"0001"
"1,2,3,4"
"test02"
"20000"
"0002"
"5,6,7,8"