I'm struggling with the chef learning curve. What is the difference between these two commands, and why are there two of them ?
knife cookbook: The knife cookbook subcommand is used to interact with cookbooks that are located on the Chef server or the local chef-repo.
$ knife cookbook create a_knife_cookbook $ ls -a CHANGELOG.md README.md attributes definitions files libraries metadata.rb providers recipes resources templates
chef generate cookbook: The chef generate cookbook subcommand is used to generate a cookbook.
$ chef generate cookbook a_chef_cookbook $ ls -a .gitignore .kitchen.yml Berksfile README.md chefignore metadata.rb recipes spec test
Cookbooks are fundamental working units of Chef, which consists of all the details related to working units, having the capability to modify configuration and the state of any system configured as a node on Chef infrastructure. Cookbooks can perform multiple tasks.
Cookbooks are a collection of recipes. Apart from recipes, cookbooks contain other elements like metadata, attributes, libraries, resources, templates, and tests which helps the nodes to achieve their desired state. Cookbooks can be created by Chef commands or by the Chef command-line tool called Knife.
Knife is Chef's command-line tool to interact with the Chef server. One uses it for uploading cookbooks and managing other aspects of Chef. It provides an interface between the chefDK (Repo) on the local machine and the Chef server. It helps in managing − Chef nodes.
knife cookbook create
is the legacy way to create a cookbook, it builds the structure of a cookbook with all possible directories.
chef generate cookbook
is part of Chef-DK and aims at generating a testable cookbook structure with minimal directories to use in test-kitchen.
Both can be tweaked, the chef generate
is easiest to tweak as the command has been written in this way to allow all to build the cookbook structure that better fits their needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With