Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Create and use multiple knife.rb files in Chef

branch: master

Merge pull request #19 from jossy/master

Fixed some angle brackets for Markdown

========== NOTE ==============

I am no longer using Knife Block at work and I do not have time to maintain it in my spare time owing to my personal life.

If you wish to submit a patch, please do so and I will get around to merging it when I can.

Sorry for any inconvenience.

latest commit 4452d8fc62
Matthew Macdonald-Wallace proffalken authored
Octocat-spinner-32 lib Fix the bug that config[:config_file] is overwriten January 09, 2014
Octocat-spinner-32 test Adds additional setup to make TravisCI happy November 12, 2013
Octocat-spinner-32 .gitignore Initial import March 26, 2012
Octocat-spinner-32 .travis.yml bumped version and updated for travis-ci September 20, 2013
Octocat-spinner-32 Gemfile need to install the chef gem for testing September 24, 2013
Octocat-spinner-32 LICENSE Initial import March 26, 2012
Octocat-spinner-32 Fixed some angle brackets for Markdown April 11, 2014
Octocat-spinner-32 Rakefile This commit is required because travis CI requires September 20, 2013
Octocat-spinner-32 knife-block.gemspec Add license to gemspec March 09, 2014

Knife Block

Green and Secure IT Limited often have a need to work with multiple chef servers at the same time, be it due to testing/development/live scenarios or purely through working for a number of clients at once.

The knife block plugin has been created to enable the use of multiple knife.rb files against multiple chef servers.

The premise is that you have a "block" in which you store all your "knives" and you can choose the one best suited to the task.


At present, knife-block requires ruby 1.9.2 or above. This is owing to the use of "Dir.home()" to find a user's home directory.


gem install knife-block

How does it work?

Knife looks for knife.rb in ~/.chef - all this script does is create a symlink from the required configuration to knife.rb so that knife can act on the appropriate server.

Create a knife-<service_name>.rb configuration file in your ~/.chef directory for each Chef server that you wish to connect to.

Please note - this script will check to see if knife.rb exists and whether it is a symlink or not.

If knife.rb is not a symlink, the program will exit immediately and tell you what to do.

List all available servers

(This command will also tell you which server is currently selected)

knife block list

The available chef servers are:
    * local-testing [ Currently Selected ]
    * opscode-hosted-chef

Change to a new server

knife block use <server_name>

You are asking to change from local-testing to opscode-hosted-chef. Are you sure? (Y/N) y
The knife configuration has been updated to use opscode-hosted-chef

Create a new server

(Launches "knife configure" and creates $HOME/.chef/knife-<friendlyname>.rb)

knife block new <friendlyname>

Berkshelf integration

Knife block supports Berkshelf, however, the berkshelf config files must be manually created and named "config-<block>.json" and put in the Berkshelf directory (typically ~/.berkshelf). In the future, these files could be automatically created by knife block.

These knife plugins are supplied without any warranty or guarantees regarding suitability for purpose.

The code requires far more tests than the simple one that currently exists.

Having said all of that, it works for us!

Copyright: Green and Secure IT Limited 2012

License: Apache 2 (

Something went wrong with that request. Please try again.