[chef] nested data bag data to template file returns “can't convert String into Integer"


Chronological Thread 
  • From: < >
  • To:
  • Subject: [chef] nested data bag data to template file returns “can't convert String into Integer"
  • Date: Tue, 25 Jun 2013 08:10:00 -0700 (PDT)

Hello,

I'm creating simple test recipe with a template and data bag. What I'm trying
to do is creating a config file from data bag that has simple nested
information, but I receive error "can't convert String into Integer" and I
can't find how to get data bag item "part.name"

Here are my setting files.

1) recipe/default.rb
data1 = data_bag_item( 'mytest', 'qa' )['test']
data2 = data_bag_item( 'mytest', 'qa' )
template "/opt/env/test.cfg" do
  source "test.erb"
  action :create_if_missing
  mode 0664
  owner "root"
  group "root"
  variables({
     :pepe1 => data1['part.name'],
     :pepe2 => data2['transport.tcp.ip2']
  })
end

2)my data bag named "mytest"
test.json
{
        "test":[
        {
            "part.name": "L12",
            "transport.tcp.ip": "111.111.111.111",
            "transport.tcp.port": "9199"
        }
        ],
        "transport.tcp.ip2": "222.222.222.222",
    "id": "qa"
}

$knife data bag show mytest qa
id:                qa
test:
  part.name:          L12
  transport.tcp.ip:   111.111.111.111
  transport.tcp.port: 9199
transport.tcp.ip2: 222.222.222.222

3)template file test.erb

part.name=<%= @pepe1 %>
transport.tcp.binding=<%= @pepe2 %>


Error returns when I run chef-client on my server, 

[2013-06-24T19:50:38+00:00] DEBUG: filtered backtrace of compile error:
/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:in
[]',/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:inblock in
from_file',/var/chef/cache/cookbooks/config_test/recipes/default.rb:12:in
from_file' [2013-06-24T19:50:38+00:00] DEBUG: filtered backtrace of compile
error:
/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:in[]',/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:in
block in
from_file',/var/chef/cache/cookbooks/config_test/recipes/default.rb:12:infrom_file'
[2013-06-24T19:50:38+00:00] DEBUG: backtrace entry for compile error:
'/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:in `[]''
[2013-06-24T19:50:38+00:00] DEBUG: Line number of compile error: '19'

Recipe Compile Error in
/var/chef/cache/cookbooks/config_test/recipes/default.rb

TypeError

can't convert String into Integer

Cookbook Trace:

/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:in []'
/var/chef/cache/cookbooks/config_test/recipes/default.rb:19:inblock in
from_file' /var/chef/cache/cookbooks/config_test/recipes/default.rb:12:in
`from_file'

Relevant File Content:

/var/chef/cache/cookbooks/config_test/recipes/default.rb:

12: template "/opt/env/test.cfg" do
13: source "test.erb"
14: action :create_if_missing
15: mode 0664
16: owner "root"
17: group "root"
18: variables({
19>> :pepe1 => data1['part.name'],
20: :pepe2 => data2['transport.tcp.ip2']
21: })
22: end 23:

I tried many things and if I comment out "pepe1 => data1['part.name'],", then
:pepe2 => data2['transport.tcp.ip2'] works fine. only nested data "part.name"
cannot be set to @pepe1.

Does anyone knows why I receive the errors?

thanks,



Archive powered by MHonArc 2.6.16.

§