LinuxCommandLibrary

knife

Manage Chef infrastructure from the command line

TLDR

Bootstrap a new node

$ knife bootstrap [fqdn_or_ip]
copy

List all registered nodes
$ knife node list
copy

Show a node
$ knife node show [node_name]
copy

Edit a node
$ knife node edit [node_name]
copy

Edit a role
$ knife role edit [role_name]
copy

View a data bag
$ knife data bag show [data_bag_name] [data_bag_item]
copy

Upload a local cookbook to the Chef server
$ knife cookbook upload [cookbook_name]
copy

SYNOPSIS

knife [SUBCOMMAND] [OPTIONS]

PARAMETERS

--config FILE
    Path to knife configuration file (knife.rb)

--log-level LEVEL
    Logging level: debug|info|warn|error|fatal

--log-location FILE
    Path to log file

-c FILE, --config FILE
    Configuration file path

-i, --initial
    Install without Chef Server interaction

-j JSON, --json-attribute JSON
    Load attribute file as JSON

-F FORMAT, --format FORMAT
    Output format: summary|json|yaml|pprint

--override-runlist RUN_LIST
    Override node's run list

-E ENVIRONMENT, --environment ENVIRONMENT
    Set Chef environment

--validation-client-name NAME
    Validation client name

--node-ssl-verify
    Verify SSL peer (default true)

-V, --version
    Display version

-h, --help
    Show help

DESCRIPTION

Knife is the command-line interface for Chef, an automation platform used for configuration management, application deployment, and infrastructure orchestration. It enables interaction with a Chef Server to manage resources like cookbooks, recipes, nodes, roles, environments, and data bags.

Administrators use knife to bootstrap nodes, upload cookbooks, search and edit node attributes, execute commands remotely, and perform bulk operations. Subcommands like knife cookbook upload, knife node list, and knife ssh streamline DevOps workflows.

Configuration occurs via a knife.rb file specifying the Chef Server URL, client key, and validation client. Knife supports plugins for extended functionality and formats output in JSON, YAML, or text. It's Ruby-based, requiring the Chef DK or Workstation for installation, and is pivotal in hybrid cloud environments for idempotent infrastructure as code.

CAVEATS

Requires Chef Workstation or gem installation; not a standard Linux utility. Needs valid knife.rb and private key. Subcommand-specific options vary; use knife SUBCOMMAND -h for details.

COMMON SUBCOMMANDS

knife cookbook (manage cookbooks), knife node (node CRUD), knife role (roles), knife bootstrap (node init), knife ssh (remote exec)

CONFIGURATION FILE

Edit ~/.chef/knife.rb:
log_level :info
log_location STDOUT
node_name 'client'
client_key '/path/to/key.pem'
chef_server_url 'https://server/organizations/org'

HISTORY

Developed by Opscode (now Chef Software) in 2009 with Chef 0.8 release. Evolved through Chef versions, integrating cloud plugins (EC2, Rackspace). Became core to Chef Infra Client; latest at Chef 18+ with modern auth (Chef Automate). Widely used in enterprise automation since early 2010s.

SEE ALSO

chef-client(8), chef-solo(8), ohai(8)

Copied to clipboard