
Chef Cookbook
By :

Knife comes with a set of commands out-of-the-box. The built-in commands deal with the basic elements of Chef-like cookbooks, roles, data bags, and so on. However, it would be nice to use knife for more than just the basic stuff. Fortunately, knife comes with a plugin API and there are already a host of useful knife plugins built by the makers of Chef and the Chef community.
Make sure you have an account at
Amazon Web Services (AWS) if you want to follow along and try out the knife-ec2
plugin. There are knife plugins available for most Cloud providers. Go through the There's more… section of this recipe for a list.
Let's see which knife plugins are available, and try to use one to manage Amazon EC2 instances:
knife
plugins that are shipped as Ruby gems using the chef
command-line tool:mma@laptop:~/chef-repo $ chef gem search -r knife- *** REMOTE GEMS *** ...TRUNCATED OUTPUT... knife-azure (1.6.0) ...TRUNCATED OUTPUT... knife-ec2 (0.13.0) ...TRUNCATED OUTPUT...
mma@laptop:~/chef-repo $ chef gem install knife-ec2 Building native extensions. This could take a while... ...TRUNCATED OUTPUT... Fetching: knife-ec2-0.13.0.gem (100%) Successfully installed knife-ec2-0.13.0 ...TRUNCATED OUTPUT... 6 gems installed
knife ec2
plugin. Please use your own AWS credentials instead of XXX
and YYYYY
:mma@laptop:~/chef-repo $ knife ec2 flavor list --aws-access-key-id XXX --aws-secret-access-key YYYYY ID Name Arch RAM Disk Cores c1.medium High-CPU Medium 32-bit 1740.8 350 GB 5 …TRUNCATED OUTPUT… m2.xlarge High-Memory Extra Large 64-bit 17510. 420 GB 6.5 t1.micro Micro Instance 0-bit 613 0 GB 2
Knife looks for plugins in various places.
First, it looks into the .chef
directory, which is located inside your current Chef repository, to find plugins specific to this repository:
./.chef/plugins/knife/
Then, it looks into the .chef
directory, which is located in your home directory, to find plugins that you want to use in all your Chef repositories:
~/.chef/plugins/knife/
Finally, it looks for installed gems. Knife will load all the code from any chef/knife/
directory found in your installed Ruby gems. This is the most common way of using plugins developed by Chef or the Chef community.
There are hundreds of knife plugins, including plugins for most of the major Cloud providers, as well as the major virtualization technologies, such as VMware, vSphere, and OpenStack, among others.
Change the font size
Change margin width
Change background colour