Chef Commands

Chef Commands Cheat Sheet
chef –version

Displays the installed Chef Workstation version.

chef generate cookbook <cookbook_name>

Generates a new cookbook with the specified name.

chef generate recipe <cookbook_name> <recipe_name>

Generates a new recipe within an existing cookbook.

chef generate attribute <cookbook_name> <attribute_name>

Generates an attributes file within a cookbook.

chef generate template <cookbook_name> <template_name>

Generates a template file within a cookbook.

chef generate file <cookbook_name> <file_name>

Generates a static file within a cookbook.

chef exec knife cookbook upload <cookbook_name>

Uploads a specific cookbook to the Chef Infra Server.

chef exec knife cookbook upload <cookbook_name> -o cookbooks/

Uploads a cookbook from a specific directory to the Chef Infra Server.

chef exec knife cookbook upload -a

Uploads all cookbooks to the Chef Infra Server.

chef exec knife cookbook show <cookbook_name>

Shows the recipes in a cookbook on the Chef Infra Server.

chef exec knife cookbook show <cookbook_name> <recipe_name>

Shows the content of a specific recipe in a cookbook on the Chef Infra Server.

chef exec knife cookbook list

Lists all cookbooks on the Chef Infra Server.

chef exec knife role create <role_name>

Creates a new role on the Chef Infra Server.

chef exec knife role show <role_name>

Shows the details of a role on the Chef Infra Server.

chef exec knife role edit <role_name>

Opens the role data in an editor to modify it.

chef exec knife role from file <role_file.json>

Creates or updates a role from a JSON file.

chef exec knife role delete <role_name>

Deletes a role from the Chef Infra Server.

chef exec knife node list

Lists all nodes registered with the Chef Infra Server.

chef exec knife node show <node_name>

Shows the details of a specific node on the Chef Infra Server.

chef exec knife node edit <node_name>

Opens the node data in an editor to modify it.

chef exec knife node delete <node_name>

Deletes a node from the Chef Infra Server.

chef exec knife environment create <environment_name> -d ‘Description of environment’

Creates a new environment on the Chef Infra Server.

chef exec knife environment show <environment_name>

Shows the details of an environment on the Chef Infra Server.

chef exec knife environment edit <environment_name>

Opens the environment data in an editor to modify it.

chef exec knife environment from file <environment_file.json>

Creates or updates an environment from a JSON file.

chef exec knife environment delete <environment_name>

Deletes an environment from the Chef Infra Server.

chef exec knife client list

Lists all clients registered with the Chef Infra Server.

chef exec knife client show <client_name>

Shows the details of a specific client on the Chef Infra Server.

chef exec knife client delete <client_name>

Deletes a client from the Chef Infra Server.

Chef Client Commands (Run on Nodes)

chef-client

Runs the Chef client, applying configurations to the node.

chef-client -L debug

Runs the Chef client with debug logging for more verbose output.

chef-client -o “recipe[cookbook_name]”

Runs the Chef client and executes a specific recipe.

chef-client -j /path/to/node.json

Runs the Chef client using a specific node JSON file.