0

I'm trying to use only one file in my Data Bag to contain multiple items (specifically for the users cookbook). All samples show isolated JSON objects. How do I store multiple ones in one file?

I've tried

{
  "id": "1"
},
{
  "id": "2"
}

and

[
    {
      "id": "1"
    },
    {
      "id": "2"
    }
]

and

{
  "id": "1"
}
{
  "id": "2"
}

I'm getting:

Net::HTTPFatalError: users_manage[xxxxx] (common::default line 76) had an error: Net::HTTPFatalError: 500 "Internal Server Error"
/opt/chef/embedded/lib/ruby/2.1.0/net/http/response.rb:119:in `error!'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/http.rb:145:in `request'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/http.rb:110:in `get'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/search/query.rb:158:in `call_rest_service'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/search/query.rb:87:in `search'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/dsl/data_query.rb:39:in `search'

I'm using chef-solo -z with the chef-solo-search cookbook.

Can't I pass an array of items from one file?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
aaro
  • 11
  • 4
  • Worth noting, there is no such thing as `chef-solo -z`. Either use `chef-client -z` or `chef-solo` + `chef-solo-search`. One or the other, not both. – coderanger May 09 '16 at 17:57

2 Answers2

0

You do not store multiple items in one data bag file in Chef. Just specify it in separate files. This is, how Chef works.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
0

Can you try something like: { "id": "users", "users": [ { ... user 1 info ... }, { ... user 2 info ... }, { ... user 3 info ... }, ... ] }

Martin
  • 2,815
  • 1
  • 21
  • 30
  • That would at least not be compatible with the _users_ cookbook. Sure you can squeeze all data into one item of a data bag, but that's just not how it's meant to be. – StephenKing May 09 '16 at 15:29
  • tried it anyway - seems it's can't parse the object: ` NoMethodError ------------- undefined method \`each' for nil:NilClass Cookbook Trace: --------------- /srv/chef/local-mode-cache/cache/cookbooks/users/providers/manage.rb:60:in \`block (2 levels) in class_from_file' /srv/chef/local-mode-cache/cache/cookbooks/users/providers/manage.rb:58:in \`block in class_from_file' ` – aaro May 09 '16 at 15:38