Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer
    
Thanks, that's exactly the step I was missing. The documentation didn't make it clear that you had to use the create step first, even if you're creating the new data bag from a pre-existing file. –  ellisera Oct 18 '12 at 20:28

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 server data bag's list:

$> 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 OPSCODE wiki].

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.