OverviewThis page describes how to launch API-driven "Cloud" servers with Knife and automatically run Chef on them.This page covers the general use of the available cloud plugins. Reference documentation for the individual plugins is maintained in the README of the plugin's code repository, linked below where available. Currently supported services (version 0.10.0 with plugins):* Amazon EC2 These are supported via sub-commands in knife that use the Ruby library fog. During the "bootstrap" process that runs Chef, knife will SSH to the systems, and uses the net-ssh-multi library. Finally, knife uses colorized output via highline. You will need to install the fog, net-ssh-multi and highline gems / libraries on your local management workstation where you use knife. On Ubuntu you will also need to install some additional apt packages in order to compile the nokogiri gem (a fog dependency): Once complete, you'd move on to continuing to setup knife with your "cloud" credentials. Cloud CredentialsAdd the Cloud Credentials to your knife.rb. They are specifically named for each of the service providers Knife supports as keys under the knife configuration option. Add the appropriate lines for your preferred Cloud Computing service to your knife.rb. |
Our friends at Agile Web Operations provided this Blog Post on Amazon EC2 Instances Using Knife. Check it out!
Community member Edward Sargisson has a nice blog post up on Keeping an Amazon Elastic Compute Cloud (EC2) Instance Up with Chef and Auto Scaling.
Opscode joins Brady Murray from Eucalyptus Systems to conduct a Webinar on how to Build Automated Private Cloud Infrastructure With Chef & Eucalyptus. Check it out!
Community member Steven Craig has a most excellent blog post providing an all-in-one to get you from zero to N-1 fully chef-managed Fedora Amazon EC2 instances backed with custom EBS root devices in less than 60 minutes!. Worthwhile! |
Cloud Sub-commands
Cloud sub-commands for knife are available as Knife Plugins. The following plugins are provided by Opscode as RubyGems. Install the desired plugin to make the sub-commands described below available.
Installing the knife-ec2 plugin The sub-commands for cloud management in knife follow the pattern: Where service is ec2, rackspace, openstack, bluebox, openstack, or terremark, euca each of the services has a server create sub-command that uses their API to launch a new instance of the specified flavor or image with a run list. Enclose the run list items in quotes, as the brackets for role[thing] or recipe[thing] may be interpreted by your login shell. Multiple items can be specified as a comma separated list. Examples Launch a new EC2 instance with the webserver role EC2 Note: The AMI used above is just an example. You should use the most current AMI's for your OS. For instance: the Ubuntu AMIs are found at their site, in the version subdirectories under "releases". To launch a new Rackspace instance with the webserver role
See the Knife documentation for more information on the syntax for the subcommands and further options. Instance BootstrapThe server creation sub-command bootstrap the instance. When the instance is launched, knife determines whether it is available, and once it is, ssh's to the instance using the specified username (or your local user if none specified) and does the following:
Once the Chef run is complete, the new instance will be registered with the Chef Server and be saved as a node object. This process does not set up the Chef Client service, you'll need to add a recipe in the run list that does this. You can see the config file that will be copied by creating one with: The client.rb and validation.pem will be copied to the specified directory, in this case client-config. If The Run Does Not CompleteThe run list for the first run of a newly provisioned node is passed in by knife as a file with the special command line: At the end of the first run, the node object is saved with this list, shows up on the console and knife commands, and is used on subsequent chef-client runs. If the run does not complete, (the instance is created but the installs are not completed), then the node with the run list applied to it is never saved. Run the above command if this occurs. The normal state is for the first chef-client run to complete - an incomplete run is the sort of thing that will happen while debugging changes and new recipes. A typical cause is an unmet dependency in cookbooks. Review the metadata.rb files of the cookbooks in your base role, or any other roles being established in the initial run for any dependencies. Bootstrap SubcommandCurrently, the bootstrap subcommand is used on EC2 and Rackspace instances. This isn't cloud-provider specific, and can be used on any kind of system, like a bare metal server or a VMware machine. The bootstrap sub-command is not used by the terremark or openstack or euca server creation yet:
SSH ConfigurationThe bootstrap process uses SSH, so you'll need to configure your system to SSH in a particular way. The easiest way to make sure that SSH uses your Cloud service's SSH key is to add it to your SSH key agent. For example, if you have saved the private key for EC2 to ~/.ssh/ec2_ssh_key: On Mac OS X Snow Leopard, ssh-agent is already running by default when you use Terminal. You also need to specify the current user to SSH as:
Connecting to your cloud from its external FQDNBy default, knife will use the internal FQDN to connect to nodes. When connecting from outside of your cloud you may need to force this to use the external FQDN. You will want to avoid doing this unless necessary, as this will route all traffic out through the NAT infrustructure and could cause performance hits or additional usage charges. If you're sure you want to do this, you can do it with the -a option, such as in this example: Deleting a serverTo delete a server once you are done using it, you will want to use this command: The instance id can be located with the command 'knife <plugin name> server list' or 'knife status'. For example, you could delete a server using these commands if you were using the rackspace plugin: Make sure that you also clean up the associated 'node' and 'client' objects from hosted chef:
|
|
|



7 Comments
comments.show.hideAug 30, 2010
ajay
When trying to create a new rackspace instance, I encountered the following error
It appears that there is a minor bug in /usr/lib/ruby/1.8/chef/knife/ssh.rb, at the top, it checks for net-ssh version >= 2.0.23 but at the bottom, where it throws this error, it checks for
I think it should be
I am running ubuntu 10.04 and chef via 'deb http://apt.opscode.com/ lucid main' in /etc/apt/sources.list.d/opscode.list
Dec 17, 2010
Eberhard Wolff
I believe the EC setup should really be
knife ec2 server create "role[webserver]" -i ami-2d4aa444 -G default -x ubuntu -S us-east-01
-G default is the security group - make sure that you are using a group that allows access to all port you want (80 for HTTP for example)
-S us-east-01 is the ssh key. If non is specified it seems you will be unable to log into the new EC2 instance. You will need to set up this key for ssh_agent as explained above.
Feb 01, 2011
Cameron Pope
I've run into issues on some platforms where the knife command fails to launch an EC2 instance due to certificate validation issues. This is not a Chef or Knife problem, and it seems to happen from time to time. (https://github.com/geemus/excon/issues/issue/13)
The best workaround that I have found so far is to add the following to the bottom of .chef/knife.rb
require 'excon'
Excon.ssl_verify_peer = false
It's certainly not the ideal solution, but I spent several hours figuring that out, and it's better than not being able to bootstrap servers.
Feb 16, 2011
korrio
Apologies in advance if I'm posting this in the wrong place...
Question: Is ubuntu still the only OS supported by this process?
I tried launching an EC2 instance that was Fedora based, and things died out I think in or around trying to build the native Gem extensions...
I noticed the comment above saying that "The current implementation is opinionated and is focused on Ubuntu servers, but we are working to support other platforms and methods." but when I went to the ticket (http://tickets.opscode.com/browse/CHEF-1376) it said it was a dup of (http://tickets.opscode.com/browse/CHEF-1393) which is marked as closed...
So... any thoughts on what I'm doing wrong.
Nov 15, 2011
Matt Williams
I'd like to be able to provision a cloud instance and have the chef-client daemonize as is possible with the knife bootstrap method. What's the best approach to this?
Nov 15, 2011
Joshua Timberman
Matt,
Use Opscode's "chef-client" cookbook. It provides a service recipe that will set up chef-client to run as a daemon.
Nov 15, 2011
Matt Williams
This worked well - thanks.