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

Let's say you have a standard Chef repository with directories as follows:

cookbooks
data_bags
environments
roles

Is there way to upload it all in one go? Otherwise you have to do this:

knife cookbook upload -a
knife data bag from file data_bags/*.json
knife environment from file environments/*.rb
knife role from file roles/*.json

Perhaps there are third-party tools to do this kind of thing?

share|improve this question

3 Answers 3

You could write a simple bash script to do that like:

#!/bin/sh

for file in `ls cookbooks`;do
 [ -d $file ] && knife cookbook upload cookbooks/$file
done
for file in `ls data_bags | grep \.json$`;do
 knife data bag from file data_bags/$file
done
for file in `ls environments | grep \.rb$`;do
 knife environment from file environments/$file
done
for file in `ls roles | grep \.json$`;do
 knife role from file roles/$file
done

then call it using ./script.sh, this will do everything automatically.

share|improve this answer
1  
Um, well, obviously. :/ –  Steve Bennett Sep 6 '12 at 0:46

I wrote a small knife plugin called sync-all described below that accomplishes this as well:
https://github.com/cdoughty77/knife-sync-all

share|improve this answer

Make sure you are using ruby 1.9, then install knife-essentials

$ gem install knife-essentials

Then add the following to ~/.chef/knife.rb

repo_mode 'everything'
versioned_cookbooks true
chef_repo_path 'PATH/TO/chef-repo'

Then you can download/upload your entire server, or just parts of it. Downloading will put a lot of .json files in your chef-repo, good for backups I found.

$ knife download /
$ knife upload /
$ knife upload /clients

Also note that if you have roles stored as ruby files (e.g: roles/*.rb), you will need to convert them to json. Then you can re-download them from chef server as json. For example:

  1. knife role from file roles/*.rb
  2. knife download roles/

This method is also used to upgrade from chef server 10 to 11.

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.