Introduction
A cookbook is a basic unit of configuration and policy distribution in Chef Infra. It defines a scenario and keeps everything needed to support it. The cookbook organizes material into recipes. The cookbook can do multiple tasks—cookbooks store values about the needed state of the node. And Knife is a tool that interfaces between the Chef Infra Server and local Chef-repo. The knife cookbook subcommand interacts with cookbooks in the local chef-repo or the Chef Infra server.

In this blog, we will discuss the various functions of knife cookbooks in detail. So, Stay till the end, and Let’s get started!
Arguments
bulk delete
bulk delete argument is used to delete files of cookbooks that match a pattern specified by a regular expression.
| Syntax | knife cookbook bulk delete REGEX (options) |
| Options | -p, --purge |
| Example | knife cookbook bulk delete “^[0-9] {3} $” -p |
delete
delete argument is used to delete a particular cookbook version on the Chef Infra Server or cookbook.
| Syntax | knife cookbook delete NAME_OF_COOKBOOK [VERSION_OF_COOKBOOK] (options) |
| Options | -a, --all |
| Example | knife cookbook delete smartmon 0.8 |
download
download argument is used for downloading a cookbook from the Chef Infra Server to the present directory.
| Syntax | knife cookbook download NAME_OF_COOKBOOK [VERSION_OF_COOKBOOK] (options) |
| Options |
-d DOWNLOAD_DIRECTORY, --dir DOWNLOAD_DIRECTORY, -N, --latest, -f, --force |
| Example | knife cookbook download thiscookbook |
list
List argument is used to see a list of cookbooks that are available at the moment on the Chef Infra Server. The list will only store the latest version for each cookbook by default.
| Syntax | knife cookbook list (options) |
| Options | -a, -w, --all, --with-uri |
| Example | knife cookbook list |
metadata
metadata argument is used to create the metadata for one or more than one cookbook.
| Syntax | knife cookbook metadata (options) |
| Options | -a, -o PATH: PATH, --all, --cookbook-path PATH: PATH |
| Example | knife cookbook metadata -a |
metadata from file
metadata from file argument is used to load the metadata for the cookbook from a file.
| Syntax | knife cookbook metadata from file FILE |
| Options | This argument does not contain any options. |
| example | knife cookbook metadata from file /the/filepath |
show
show argument is used to view information about a cookbook, files, parts of a cookbook(recipes, libraries, providers, attributes, resources, and templates), or a file connected with a cookbook.
| Syntax | knife cookbook show NAME_OF_COOKBOOK [VERSION_OF_COOKBOOK] [PART...] [FILE_NAME] (options) |
| Options |
|
Examples
To get the list of present versions of a cookbook named getting-started, use the following command:
Knife cookbook show getting-started
To display the list of data about a cookbook using the version and the name of the cookbook, use the following command:
knife cookbook show getting-started 0.3.0
To only see the data about the templates, you can use the following command:
knife cookbook show getting-started 0.3.0 templates
To see the information in JSON format, you can use the -F common option; you can use the following command:
knife cookbook show devops -F json
test
test argument is used to test a cookbook for syntax errors. This test argument uses RUBY syntax checking to verify each file in a cookbook that ends in Embedded Ruby and .rb.
| Syntax | knife cookbook test NAME_OF_COOKBOOK (options) |
| Options | -a, -o PATH:PATH, --all, --cookbook-path PATH:PATH |
| Example | knife cookbook test cookbook_name |
upload
upload argument is used to upload one or more than one cookbooks from the local repository into the Chef Infra Server. Files already uploaded on the Chef Infra server will not be uploaded.
| Syntax | knife cookbook upload [NAME_OF_COOKBOOK...] (options) |
| Options |
|
Examples
To upload a cookbook, use the following command:
knife cookbook upload name_of_cookbook
To upload a cookbook and then freeze, you can use the following command:
knife cookbook upload redis --freeze




