Skip to end of metadata
Go to start of metadata


Overview

Knife is a command-line tool that comes with Chef.

It is used by administrators to interact with the Chef Server API, the local Chef repository and can be used to create, edit, view, list, tag and delete nodes.


Knife's node sub-command provides the ability to manage nodes.

For more information about Knife, refer to the Knife documentation.
See Nodes for more information on nodes.

       
Knife commands all have the same form



Creating a node with Knife

Create a new node.

Note: A node is created the first time you run chef-client, or when you use Knife Bootstrap commands.
Use of this knife subcommand to create nodes isn't required if you have taken either of those steps.

Unless the --no-editor option is given, an empty node object will be created and displayed in your text editor. If the editor exits with a successful exit status, the node data will be posted to the Chef Server to create the node.

Through an EDITOR

  1. set EDITOR environment variable, for example:
  2. create a new node, for example:
  3. enter the content of the node in JSON, for example:
  4. Save it.
    If there isn't an existing node, you will see a warning message about that, which is normal. For example:

Create a node from a JSON file

Editing a node with Knife

Edit an existing node.

The JSON description of the node will be opened with EDITOR and saved back to the Chef Server once editing is complete. See Nodes for more information on the node description.

Through an EDITOR

  1. set EDITOR environment variable, for example:
  2. edit a node, for example:
  3. Update the JSON in the editor.
  4. Save it.

Add to a node's run list.

This will add RUNLIST_ITEM to the run list of NODE.

Additional Options:

  • -a, --after ITEM:
    Place the ENTRY in the run list after ITEM

Details:
Run list items may be either roles or recipes.

Recipe addition

When adding a recipe to a run list, there are several valid formats:

  • Fully Qualified Format:
    'recipe[COOKBOOK::RECIPE_NAME]', for example, 'recipe[chef::client]'
  • Cookbook Recipe Format:
    For brevity, the recipe part of the fully qualified format may be omitted, and recipes specified as 'COOKBOOK::RECIPE_NAME', e.g., 'chef-client::service
  • Default Recipe Format:
    When adding the default recipe of a cookbook to a run list, the recipe name may be omitted as well, e.g., chef-client::default may be written as just chef-client
Roles addition

Roles can be added to a run list using the following format:

Note that you need to put the role in quotes when using the knife node run_list add subcommand.

Example:

Remove an item from a node's run list.

Viewing or Showing a node with Knife

Displays information about a node.

Knife 0.10+ and above do not display all node attributes by default. The full list of attributes is very large and are thus suppressed from the default output. You can see all of the node data by choosing JSON formatted output via the -Fj option.

Additional Options:

  • -a, --attribute ATTR:
    Show only one attribute
  • -r, --run-list:
    Show only the run list
  • -F, --format FORMAT:
    Display the node in a different format.
  • -m, --medium:
    Display more, but not all, of the node's data when using the default summary format

Examples

Note that when displaying a single attribute, the value shown is determined via attribute precedence. (See Attributes for more information.)

Examples:
Viewing all data in a node:

Viewing the run list of a node

Listing the nodes

List all nodes.

Additional Options:

  • -w, --with-uri:
    Show corresponding URIs

Examples:

Deleting a node with Knife

Removing a node from being managed via the Chef Server.

bulk delete

Deletes nodes for which the name matches the regular expression on the Chef Server. The regular expression should be given in quotes, and should not be surrounded with forward slashes.

delete an individual node

Deletes a node from the Chef Server.

Additional Options:

  • -a, --all:
    Display all node data in the editor. By default, default, override, and automatic attributes are not shown.

Note: Deleting the node does not delete any corresponding API client for the node.

Using TAGS

You can also "tag" nodes and then manage them with knife through those tags.

Creating a new node with a TAG

List a node's TAGs

Deleting Node based on TAGs







Managing Environments With Knife


Managing Roles With Knife



Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.