[chef] Re: Data bag usage in recipe. Failure. HTTP Request Returned 404 Object Not Found


Chronological Thread 
  • From: Jeff Byrnes < >
  • To:
  • Subject: [chef] Re: Data bag usage in recipe. Failure. HTTP Request Returned 404 Object Not Found
  • Date: Fri, 19 Dec 2014 16:35:24 -0500

The confusion here is that the data bag item is what you refer as the data bag. In your case, the data bag is `db_databag`, and the data bag item is `tenant`.

That is, this is the data bag item:

{
  "id": "tenant",
  "tenant_name": "db_test1",
  "db_name": "db_name1",
  "path": "path1",
  "any_other_stuff": "some_stuff1"
}

So you want to query for it like so:

tenant_data_bag = data_bag_item ‘db_databag’, ‘tenant’
tenant_name = tenant_data_bag[‘tenant_name’]
path = tenant_data_bag[‘path’]

Does that make more sense?

-- 
Jeff Byrnes
@berkleebassist
Lead DevOps Engineer
704.516.4628

On December 19, 2014 at 9:49:16 AM, ( "> ) wrote:

Hi guys,

I am really struggle with getting data bags data into my recipe:

Here is recipe:
val1 = data_bag_item('db_databag', 'tenant_name')
val2 = data_bag_item('db_databag', 'path')
val3 = data_bag_item('db_databag', 'db_name')
val4 = data_bag_item('db_databag', 'any_other_stuff')

template 'c:\test_template.txt' do
  source 'test.txt.erb'
  variables({
    :value1 => "this is FIRST #{val1}",
    :value2 => "this is SECOND #{val2}",
    :value3 => "this is THIRD #{val3}",
    :value4 => "this is FORTH #{val4}"
  })
end

Here is Data bag:
{
  "id": "tenant",
  "tenant_name": "db_test1",
  "db_name": "db_name1",
  "path": "path1",
  "any_other_stuff": "some_stuff1"
}

Here is Template file:
some text will be: <%= @value1 %>
some text will be:  <%= @value2 %>
some text will be:  <%= @value3 %>
some text will be:  <%= @value4 %>

Chef-client version I have on a client side:
C:\Users\tklym>chef-client --version
Chef: 11.16.4

Client's platform is windows 2008 R2.

And here what I get when I run chef-client:

172.26.3.36 [2014-12-19T14:43:47+00:00] INFO: Loading cookbooks
172.26.3.36 [2014-12-19T14:43:47+00:00] INFO: Storing updated cookbooks/hello/recipes/templates_with_data_bags.rb in the cache.
172.26.3.36 [2014-12-19T14:43:47+00:00] INFO: HTTP Request Returned 404 Object Not Found: Cannot load data bag item tenant_name for data bag db_databag
172.26.3.36 [2014-12-19T14:43:47+00:00] ERROR: Failed to load data bag item: "db_databag" "tenant_name"
172.26.3.36
172.26.3.36 ==================================================================== ============
172.26.3.36 Recipe Compile Error in c:/chef/cache/cookbooks/hello/recipes/templates_with_data_bags.rb
172.26.3.36 ================================================================================
172.26.3.36
172.26.3.36 Net::HTTPServerException
172.26.3.36 ------------------------
172.26.3.36 404 "Object Not Found"
172.26.3.36
172.26.3.36 Cookbook Trace:
172.26.3.36 ---------------
172.26.3.36   c:/chef/cache/cookbooks/hello/recipes/templates_with_data_bags.rb:1:in `from_file'
172.26.3.36
172.26.3.36 Relevant File Content:
172.26.3.36 ----------------------
172.26.3.36 c:/chef/cache/cookbooks/hello/recipes/templates_with_data_bags.rb:
172.26.3.36
172.26.3.36   1>> val1 = data_bag_item('db_databag', 'tenant_name')
172.26.3.36   2:  val2 = data_bag_item('db_databag', 'path')
172.26.3.36   3:  val3 = data_bag_item('db_databag', 'db_name')
172.26.3.36   4:  val4 = data_bag_item('db_databag', 'any_other_stuff')
172.26.3.36   5:
172.26.3.36   6:  template 'c:\test_template.txt' do
172.26.3.36   7:    source 'test.txt.erb'
172.26.3.36   8:    variables({
172.26.3.36   9:      :value1 => "this is FIRST #{val1}",
172.26.3.36  10:      :value2 => "this is SECOND #{val2}",
172.26.3.36
172.26.3.36 [2014-12-19T14:43:47+00:00] ERROR: Running exception handlers
172.26.3.36 [2014-12-19T14:43:47+00:00] ERROR: Exception handlers complete
172.26.3.36 [2014-12-19T14:43:47+00:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
172.26.3.36 [2014-12-19T14:43:47+00:00] INFO: Sending resource update report (run-id: 7a567034-e647-4681-a2e5-494e04dbff81)
172.26.3.36 [2014-12-19T14:43:47+00:00] FATAL: Net::HTTPServerException: 404 "Object Not Found"ERROR: Failed to execute command on 172.26.3.36 return code 1


Have no idea how to get access to data bag data... :(

Thank you in advance for your help.

Regards,
Taras.



Archive powered by MHonArc 2.6.16.

§