Why can't “knife data bag from file” find existing json file on chef server?
Summary:
I'm running into a problem with "knife data bag from file", where knife doesn't recognize the .json data bag file pulled down from a remote git repo.
Background:
I'm currently trying to transition from chef-solo use to chef server while using the cookbooks, data bags and other chef info from our remote git repo.
I've currently pulled down a copy of our git repo and set the cookbook path and data bag path in knife.rb. I also loaded the cookbooks, made adjustments, etc.
Details:
When trying to load our .json data bags by doing "knife data bag add from file FOLDER FILE" it looks like it worked until I do "knife data bag list" and it comes up blank. So I decided to try adding the edit option at the end to see what's being loaded, if it is. This is the error I get:
knife data bag from file local_settings test.json -e nano
ERROR: Could not find or open file 'test.json' in current directory or in 'data_bags/local_settings/test.json'
The data bag file does exist, in the proper location, in a tested, working json file. I've also sometimes gotten an error saying "could not open data bag "local_settings".
I would obviously like to keep the data bag path within the appropriate git repo folder to be able to keep track of changes in a more centralized location (our git repo, as opposed to the chef server).
Any solutions, advice or pointers in the right direction are appreciated.
Solution 1:
I don't think it's valid to use -e nano
option knife data bag from file
(though the command-line help implies otherwise), but it should just be ignored. That error means that knife can't find the json file you have specified. When you say that the item was in the proper location, where exactly was it? Note that knife will be looking relative to your current directory, not to your chef-repo.
With that problem fixed, you'll run into another - you need to create the data bag before you can add an item to it. It should show up in the knife data bag list
output as soon as it has been created:
$ knife data bag create local_settings
Created data_bag[local_settings]
$ knife data bag list
local_settings
The documentation for "knife data bag" can be found here: http://wiki.opscode.com/display/chef/Managing+Data+Bags+With+Knife
Solution 2:
I do
knife data bag list
and it comes up blank.
It means that data bag local_settings
is not created yet.
So, it should be created:
$> knife data bag create local_settings
Created data_bag[local_settings]
Then it should appear in list if server's data bags:
$> knife data bag list
local_settings
Then {{test.json}} data bag file could be uploaded.
Also, here is some nice explanation of what is actually going on: [link on CHEF wiki].