[chef] Fwd: Unable to use data bag


Chronological Thread 
  • From: Russell Bateman < >
  • To:
  • Subject: [chef] Fwd: Unable to use data bag
  • Date: Mon, 30 Sep 2013 11:34:27 -0600

I'm just striking out when I try to use a data bag from my recipe. It looks very simple to me, so I'm guessing there's just something very fundamental I don't get. I'm unable to mimic the opscode/Chef examples in my code. I would greatly appreciate understanding what's wrong with how I'm trying to consume the data bag.

Thanks!

I have my own Chef server set up and a number of nodes. I have had a lot of success  so far, but data bags aren't working for me.

Here's the top of my recipe; I've put some print statements in:
which = "id:" + node[ :rollup ]    # i.e.: "uas-replicaset-1"
puts "which", which
bag   = search( :rollups, which )  # TROUBLE HERE!!!!!!

puts "bag", bag

port = node[ :port ]
replSet_name = bag[ :name ]

# Copy the upstart configuration file to /etc/init...
template "/etc/init/mongodb.conf" do
  source "replica-upstart.conf.erb"
  owner "root"
  group "root"
  mode 00644           # -rw-r--r--
end

template "/data/mongodb/mongodb.conf" do
  source "replica.conf.erb"
  owner "mongodb"
  group "mongodb"
  mode 00644           # -rw-r--r--
  variables( {
      :port => port,
      :replSet => replSet_name
      }
  )
  notifies :restart, "service[ $ip_address ]", :immediately
end

Here's what's in nodes/uas-dev-db01.json:
{
    "normal": { "port" : 27017, "rollup" : "uas-replicaset-1" },
    "name": "uas-dev-db01",
    "override": { },
    .
    .
    .

Here's the data bag, data_bags/rollups/uas-replicaset-1.json:
{
    "id"          : "uas-replicaset-1",
    "name"        : "uas-replica",
    "description" : "Shard 1 replica set",
    "replica_1"   : { "hostname" : "16.86.193.117", "port" : 37017, "node" : "uas-dev-db01" },
    "replica_2"   : { "hostname" : "16.86.193.118", "port" : 37018, "node" : "uas-dev-db02" },
    "replica_3"   : { "hostname" : "16.86.193.119", "port" : 37019, "node" : "uas-dev-db03" }
}


Here's the output running
chef-client.

.
.
.
Compiling Cookbooks...
16.86.192.117
[2013-09-30T17:04:53+00:00] INFO: AptPreference light-weight provider already initialized -- overriding!
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/provider/lwrp_base.rb:97: warning: already initialized constant AptPreference
[2013-09-30T17:04:53+00:00] INFO: AptRepository light-weight provider already initialized -- overriding!
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/provider/lwrp_base.rb:97: warning: already initialized constant AptRepository
[2013-09-30T17:04:53+00:00] INFO: AptPreference light-weight resource already initialized -- overriding!
[2013-09-30T17:04:53+00:00] INFO: AptRepository light-weight resource already initialized -- overriding!
which
id:uas-replicaset-1
bag
data_bag_item[uas-replicaset-1]     <-------- I don't understand this, but I guess I'll roll with it

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/mongodb/recipes/replica.rb
================================================================================

TypeError
---------
can't convert Symbol into Integer

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/mongodb/recipes/replica.rb:15:in `[]'
  /var/chef/cache/cookbooks/mongodb/recipes/replica.rb:15:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/mongodb/recipes/replica.rb:

  8:  which = "id:" + node[ :rollup ]           # i.e.: "uas-replicaset-1"
  9:  puts "which", which
 10:  bag   = search( :rollups, which )
 11: 
 12:  puts "bag", bag
 13: 
 14:  port = node[ :port ]
 15>> replSet_name = bag[ :name ]
 16: 
 17:  # Copy the upstart configuration file to /etc/init...
 18:  template "/etc/init/mongodb.conf" do
 19:    source "replica-upstart.conf.erb"
 20:    owner "root"
 21:    group "root"
 22:    mode 00644           # -rw-r--r--
 23:  end
 24: 






Archive powered by MHonArc 2.6.16.

§