|
This manual page documents knife, a command-line utility used to interact with a Chef server directly through the RESTful API. Knife uses sub-commands to take various actions on different types of Chef objects. Some sub-commands take additional options. General options follow sub-commands and their options. A configuration file can be created for common defaults. Unless otherwise specified, output is in JSON format, and input files are also JSON format.
|
General Options
Sub-Commands
Knife sub-commands are structured as "NOUN verb NOUN (options)". The sub-commands are meant to be intuitively named.
Client Commands
Sub-commands related to working with clients, which are registered entities that access the Chef server.
Delete all the clients on the Chef server that match the regular expression.
Create a new client.
Deletes a registered client.
Edit a registered client.
List all registered clients.
Regenerate the private key for a client.
Show a client.
Cookbook Commands
Cookbooks are the fundamental unit of distribution in Chef. They encapsulate all the recipes of resources and the assets used to configure a particular aspect of the infrastructure.
Delete all the cookbooks on the Chef server that match the regular expression.
Delete a single named COOKBOOK.
Download a cookbook from the server as a gzip(1)'ed, tar(1) archive.
List all cookbooks.
Generate cookbook metadata for the named COOKBOOK.
Show the particular part of a COOKBOOK. PART can be one of: attribute definition file provider recipe resource template
Upload a cookbook to the server.
Data Bag Commands
Data bags are stores of JSON blobs. These blobs are called items. They are free form and indexed by the search mechanism on the Chef server.
Create a new data bag, or item in a data bag.
Delete a data bag, or item from a data bag.
Edit an item in a data bag.
List the available data bags.
Show a specific data bag or an item in a data bag.
Node Commands
Nodes are the entities which are configured with Chef, typically servers or workstations. Nodes are registered as a client, typcially of the same name, but a single client might represent one or more nodes.
Delete all nodes that match the regular expression.
Create a new node.
Delete a single node.
Edit a node.
Create a node from a JSON file.
List all nodes.
Add a recipe or role to the node's run_list.
Remove a recipe or role from the node's run_list.
Show a node.
Role Commands
Roles provide a mechanism to apply a set of recipes and attributes to nodes. For example, the 'webserver' role might instruct Chef to add a recipe for Apache, and specify a default domain to use.
Delete all roles that match the regular expression.
Create a new role.
Delete a role.
Edit a role.
Update a role from a file.
List roles.
Show a specific role.
General Commands
The following are general sub-commands that do not fit within the other object types used in Chef.
Create a configuration file for knife. This will prompt for values to enter into the
file. See "CONFIGURATION" below for available options.
Chef is commonly used with Amazon AWS EC2 nodes. This command will generate instance
metadata that can be used to automatically configure an EC2 instance with Chef.
The strings specified RUN LIST will be used to create the list that will make up the "run_list" JSON attribute.
This command line expects RUN LIST as space separated (not comma separated) strings. An example command line:
knife ec2 instance data "role[base]" "role[ops_master]" "recipe[nagios::server]"
Search Indexes are a powerful feature of the Chef server and the search subcommand allows searching any of the available indexes using the SOLR query syntax.
Configuration
The knife configuration file is a Ruby DSL. If it exists, knife uses the settings
for GENERAL OPTIONS defaults.
Example ~/.chef/knife.rb:
Troubleshooting
"Unauthorized 401" errors can be caused by the clock on your client machine and server not being the same. Try synchronising them, and see if that helps.