Skip to end of metadata
Go to start of metadata


Use Knife for Chef 0.9+

These AMIs reflect an older way of launching instances in EC2 for Chef.

Knife in Chef 0.9+ has the ability to create new instances from a specified AMI and "bootstrap" it by installing Ruby and Chef, and automatically runs Chef Client on it. You can read how to Launch Cloud Instances with Knife for more information.

See Canonical's list of AMIs for Ubuntu, for use with knife ec2 server create

If you prefer to Roll Your Own AMIs, rather than using Knife - for a reason that is specific to your environment - there is a section on how to do so within this document.


Recommended Use

The current recommended way to launch EC2 instances for Chef is to use the Knife sub-commands.

Rolling Your Own

If you would like to roll your own Amazon EC2 AMIs with Chef preinstalled, you can follow the same steps that were used by Opscode. These are consistent with the general Installation instructions, and use a RubyGems installation of Chef.

Some Assumptions
These steps assume you already have your Amazon EC2 credentials set up to work with the command-line API tools and have a working familiarity with the tools and EC2 concepts. In addition to installing the API tools on the instance, you should have them installed on your local system.

Launch Instances

We use Canonical's official Ubuntu images.

Commands to launch an instance of the desired AMI are listed on those pages.

Login and Start

Log into the instance as ubuntu, make sure history will not be saved and su to root.

Edit the sources and enable multiverse.

Install Ruby and RubyGems

We install Ruby from packages, but RubyGems from source, same as the Installation instructions for RubyGems. We also install the ec2-ami-tools, which come from multiverse.

Install Chef

Install the Chef gem. We only need the client. You could opt to install Chef from distribution packages if you wish, see Installing Chef Client on Ubuntu or Debian for more information.

Configure Chef Client

This section could also be handled with the normal [RubyGems Bootstrap], but doing it manually leaves fewer artifacts to clean up . We use the following config file for the client that reads the user data for the instance.

We use Runit to manage the chef-client service with a RubyGems installation. Runit uses a 'run' script and a 'log/run' script.

/etc/sv/chef-client/run
/etc/sv/chef-client/log/run

Install runit and set up the chef-client service:

Clean up

Copy EC2 Configuration

You will need to copy your EC2 certificates over with a config file.

The pk.pem and cert.pem should be the contents of the appropriate files for your EC2 credentials. The config file should have the following values set:

Source the EC2 config and set up some helper variables for creating the AMI name. Be sure to specify the correct ARCH for the instance type you're creating.

Create the AMI Bundle

Register and Release

These steps use programs that are included in the ec2-api-tools. You will need to install these for your local workstation's Operating System.

On your local workstation, repeat the variable export from above. Also make sure you are using the correct EC2 configuration. Then register the AMI manifest to generate a machine ID.

Finally, if you are making the AMI available for anyone to use, set public permission.



Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 07, 2010

    An alternative to doing the steps from "Copy EC2 configuration" is to use the automated AMI building features under Instance Actions in the AWS console. This also means you don't need the AMI tools package.

  2. Nov 16, 2010

    You mention that "These AMIs reflect an older way of launching instances in EC2 for Chef."

    Does this mean that the bootstrapped AMI approach and "knife ec2 instance data" will be deprecated?
    Launching EC2 instances with knife is fine and works well for individual instances but not
    for auto-scaling.

    The use case I have in mind is an AWS auto-scaling setup whose launch config contains instance data
    generated by "knife ec2 instance data 'role[foo]'". Does that seem reasonable?

    1. Nov 17, 2010

      We don't have any plans to remove the instance data sub command for knife, so you can continue to implement EC2 instances with this process. We may not always keep the AMIs up to date.