with chef 10 server and an admin client, I used to be able to create a data bag, then add items to it, like this:
dbag = "sam-config-#{node.chef_environment}"
begin
dbag_bag = Chef::DataBag.new
dbag_bag.name(dbag)
dbag_bag.save
rescue => e
Chef::Log.info( "Creating the data bag failed: #{e.inspect}" )
end
dbag_item = Chef::DataBagItem.new
dbag_item.data_bag(dbag)
Chef::Log.info( "Adding new item: #{id}" )
dbag_item.raw_data = item
dbag_item.save
I needed to have the data bag creation in a rescue loop because in 10 server, there was no way without triggering an exception to ask the server if the data bag existed before trying to create it, so I would either get an exception asking if it was there, or I'd get an exception asking to create it.
Now, if it doesn't exist, I get #<Net::HTTPServerException: 405 "Method Not Allowed">
Is there a new way to handle this (or perhaps a better one that works in both chef 10 and chef 11 without blowing up in my face all the time)?
Thanks!
-Jesse