What is Knife?Knife is a powerful command-line interface (CLI) that comes with Chef.It is used by administrators to interact with the Chef Server API and the local Chef repository. It provides the capability to manipulate nodes, cookbooks, roles, databags, environments, etc., and can also be used to provision cloud resources and to bootstrap systems.OverviewAs the administrators command line tool for interacting for the chef server, Knife is run from the management workstation, acting as the intersection between the Chef Server and your infrastructure. Knife interacts with the Chef Server through the same REST API that the Chef Client software uses, authenticating as an API client. Hosted Chef and Private Chef then have the additional role based authentication controls (RBAC) that authorize changes based upon users and organizations. See Authentication and Authorization for more information on this model. Knife comes with a series of built in subcommands, which provide the functionality and capability for specific actions upon cookbooks, nodes, roles, etc. within your infrastructure. Knife also has the capability to be a container for Knife Plugins - which extend its functionality beyond the built in commands to features including launching cloud instances and bootstrapping systems. There is a built in contextual help system for obtaining more information on the commands and subcommands, options for their use, or reviewing manpage documentation. When you go through Workstation Setup, one of the actions includes establishing and configuring knife for use. Subsequent modifications can be made through editing the knife.rb configuration file. Knife Built In SubcommandsThe following subcommands are built into Knife, and available for managing their respective components from the Knife command line interface. Subcommands built into Knife:
If you invoke knife with the --help option at the top level you will see options common to all subcommands.If you invoke knife with the --help option at a specific subcommand level, knife presents the options specific to that subcommand.Further, you can directly access manpages with content similar to this page using the help sub-command. Use knife help list.You can then read individual pages by using a command in the form of:Configuring Your System For KnifeKnife's configuration file is named knife.rb. Unless directly passed the configuration file location via the -c command line option, Knife searches for this configuration by searching for .chef/knife.rb, starting at the current working directory and moving upward. If no configuration is found ~/.chef/knife.rb is used if it exists. The following parameters can be set in knife.rb:
Knife PluginsAs Chef will load commands from a set of specific locations, you can create plugins for reuse across projects in your home directory, share plugins with your team by including them in your cookbook repo, and share plugins with the whole Chef community by distributing them as Ruby gems. With Chef 0.10, knife will load commands from the following locations:
See Knife Plugins for details on creating and installing plugins, and Community Plugins for a listing of plugins that have been made available by Chef community members. You can set this variable when issuing the command.Alternatively you can set the variable for the rest of your shell's session.See your shell's documentation for information on how to ensure that EDITOR is always set when you start a new shell. Command and Output OptionsCommon OptionsThe following options can be passed to any subcommand. For sub-command specific options, see the section of Knife Built In Subcommands for the relevant subcommand.
Output FormatsThe amount of content displayed and the output format can be modified by the `--format` option. If no alternate format is selected, the default is summary. Valid formats are:
For brevity, only the first character of the format is required, for example, -Fj will produce JSON format output.
|
|
|


1 Comment
comments.show.hideApr 29, 2011
Robert J. Berger
If you are using Mac OS X and want to use the knife bash completions mentioned on this page and you are using brew instead of Macports the command to install gsed is:
brew install gnu-sed
You'll also have to install bash_completion no mater if you are using Macports or brew. Some good instructions for this and other Mac OS X setup goodness at http://justinhileman.info/article/building-a-lamp-development-environment-on-snow-leopard/ Search for bash_completion on that page.