Author: Arun Bagal

Launching AWS instance using Chef server

Launching AWS instance using Chef server


                    Chef enables you to automate your infrastructure. It provides a command line tool called knife to help you manage your configurations. Using the knife EC2 plugin you can manage your Amazon EC2 instances with Chef. knife EC2 makes it possible to create and bootstrap Amazon EC2 instances in just one line – if you go through a few setup steps. Following are steps to setup your Chef installation and AWS configuration so that we can easily bootstrap new Amazon EC2 instances with Chef’s knife

Following are the steps need to launch AWS instance.

A. Installation and Configuration of Knife Ec2 instance

  1.  Instaiing knife-ec2 instance:

a. If you’re using ChefDK, simply install the Gem:
$ chef gem install knife-ec2

b. If you’re using bundler, simply add Chef and Knife EC2 to your Gemfile:
$ gem ‘knife-ec2’

c. If you are not using bundler, you can install the gem manually from Rubygems:
$ gem install knife-ec2

In my setup I used ChefDK.

2.  Add ruby’s gem path to PATH variable to work knife-ec2 with AWS

$  export PATH=/root/.chefdk/gem/ruby/2.1.0/bin:$PATH

 3. Add the AWS credentials of knife user to knife configuration file i.e ~/.chef/knife.rb.


knife[:aws_access_key_id] = “user_key_ID”
knife[:aws_secret_access_key] = “User_secret_key”


 B. Prepare SSH access to Amazon EC2 Instance.
 1. Configure Amazon Security Group
As Amazon blocks all incoming traffic to EC2 instances by default. We’ll need to open the SSH(22) port for knife to access a newly created instance. Also HTTPS(443) port to communicate launched instance’s chef client with chefserver.Just login to the AWS management console and navigate to EC2 Services Compute Security Groups default group.Then add a rule for Type SSH and HTTPS with Source Anywhere and save the new inbound rule

2. Generate Key Pair in AWS Console
To enable SSH access to Amazon EC2 instances you need to create a key pair. Amazon will install the public key of that key pair on every EC2 instance. knife will use the private key of that key pair to connect to your Amazon EC2 instances. Store the downloaded private key knife.pem in “~/.ssh/knife.pem” of ec2-user.

3. Prepare SSH configuration to avoid host key mismatch errors:
Create “/home/ec2-user/.ssh/config and add below content:
Host ec2*
StrictHostKeyChecking no
User ec2-user
IdentityFile /home/ec2-user/.ssh/knife.pem

 C. Choose an AMI for your Amazon EC2 instances
We need to choose the right AMI for region, architecture and root storage. Note down the AMI ID (ami-XXXXXXXX) to use it with knife.


D. Create an EC2 instance using Chef knife:
Now, it’s time to use knife to fire up and configure a new Amazon EC2 instance. Execute below command to create instance.
$sudo knife ec2 server create -r “recipe[dir]” -I ami-0396cd69 -f m3.large -S knife -i /home/ec2-user/.ssh/knife.pem –ssh-user ec2-user –region us-east-1 -Z us-east-1b

-r is the run_list I want to associate with the newly created node. You can put any roles and recipes you like here
-I is the AMI ID
-f is the Amazon EC2 instance type
-S is the name you gave to the SSH key pair generated in the AWS management console
-i points to the private key file of that SSH key pair as downloaded when the key pair was created in the AWS management console
–ssh-user the official EC2 AMIs use ec2-user as the default user
–region us-east-1 If you want your instances to be deployed in any specific Amazon AWS region, add this parameter and the desired region
-Z us-east-1b is the availability zone within your region

If you did not give the –r i.e run list with above mentioned command, then it throws the Exception below:

     “EXCEPTIONS : NoMethodError Undefined method ‘empty?’ for nil:NilClass”


E.   Terminate instance and delete the corresponding Chef node
$ knife ec2 server delete i-XXXXXXXX –region us-east-1
$ knife node delete i-XXXXXXXX

(i-XXXXXXXX is the ID of the instance as found in the AWS management console)

Installation of Vmware-Exsi 5.0 Server

Installation of Vmware-Exsi 5.0 Server


To get started with your installation of ESXi5, insert the ESXi5 disc into your server and start it up.

In Figure 1 below, you’ll see the first screen that greets you when you start your server. From this menu, choose the first option to start the ESXi 5 installer.

Figure 1: ESXi 5 boot menu

Once you choose the installation option, the installer provides you with a window that details the status of each file that needs to be loaded. Figure 2 shows you this screen. After that, you’re greeted with a familiar screen that shows you some information about your server, including the processor type and system RAM. The target machine for my sample installation is a virtual machine running on my laptop, hence the relatively minimal hardware configuration. You can see this screen in Figure 3.

Figure 2:Installer load status

Figure 3:Yet another boot screen!

With the preliminaries out of the way, the ESXi 5 installer truly kicks off with a welcome screen containing information regarding VMware’s Compatibility Guide. To continue with the installation process, press Enter.

Figure 4: Kick off the ESXi installation.

Of course, no installation would be complete without having to accept an end user license agreement. To accept the agreement as a part of the installer, press F11. If you don’t accept the agreement, press Escape to abort the installation. You can see this screen in Figure 5.

Figure 5: ESXi 5 end user license agreement

A location to which to install ESXi 5 is the first technical decision you have to make. In Figure 6 below, you can see that I have a single 40 GB volume from which to choose as an install location on my machine.


Figure 6: Choose an installation location for ESXi 5

Next up, choose your keyboard layout as US Default.

The root password on your ESXi 5 system is the key to your virtual kingdom, so choose with care. Make sure you provide a strong password. As you can see in figure 7, you have to provide the password twice to make sure you don’t include any typos.

Figure 7: Provide a password for the root user account

The ESXi installer now scans your system to get additional information.

Once that’s complete, you’re asked to confirm the installation by pressing the F11 button .

 Figure 8Confirm the installation

Once you initiate the installation, your selected disk will be repartitioned. Throughout the process, the installer provides you with an installation status like the one shown in Figure 9.

Figure 9Installation status

When the installation process has finished, you’ll get a message indicating such as

Figure 10:Installation is complete

The last screen you’ll see is a yellow and gray one like the one shown below. Take note of the IP address on the screen.

Figure 11: ESXi 5 server display


Thank You,

Arun Bagal.