Hosted Chef Server in AWS

Minimum Requirements

Server:

  • A T2 Micro or Medium AWS Instance is good enough
  • Ubuntu Linux as OS platform
  • Public IP address.

Work Station:

  • A T2 Micro AWS Instance is good enough or you can use your Local Machine
  • Windows or Linux OS platform
  • Chef DK installation file

Node:

  • A node can be any platform of OS and configuration
  • Depends on what you run on the node machine
  • Public IP address

Set up an AWS instance to manage:

  • Open AWS (Amazon EC2) console
  • In the navigation bar at the right top of the screen, select the preferred region.
  • From the console, choose Launch Instance.
  • Select Ubuntu AMI
  • Choose the preferred Instance Type
  • On the Configure Instance Details page, change the settings as necessary and forward to Add Storage
  • Add storage, Tags, and click next to Configure Security Group.
  • Select an existing group if already exists or create a new security group now.
  • Define the inbound rule to allow you to connect to your instance over SSH (port22) for Linux or RDP (port3389) for Windows. You can add for HTTPS, HTTP for the same.
  • Choose my IP from the source list to connect from your IP address.
  • Review and launch the instance by downloading the keypair (. PEM) file.

Download the Chef Development Kit:

  • Open https://downloads.chef.io/chefdk to download the Chef DK file.
  • Select the required versions or OS and forward to download the required DK file to your local machine
  • From this Work Station, only we can create, upload and edit Cookbooks.

Download the Chef Server:

  • Connect to your AWS Instance using Putty. To connect see the following link http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
  • Convert the .PEM file to .PPK using Puttygen which you have downloaded (Mentioned in the above link)
  • Once to connected to your machine, run the following so that newest versions of packages and their dependencies are downloaded and installed “apt-get update && apt-get upgrade -y”
  • Once done, run the following command to install Chef “curl -L https://www.opscode.com/chef/install.sh | bash”
  • Once installation is done, run the command “knife –version” which displays a version number which is currently installed in your system. Thus, Chef Workstation is installed and now you have a Chef Server and Chef Work Station ready to work.

Starter-Kit:

A Starter Kit, is a .zip file which contains all the configuration details of your organization as knife.rb file and in this .rb file you have the following details

  • node_name
  • client_key
  • chef_server_url
  • cookbook_path

Once the starter kit is downloaded, make sure that it is saved in a private place. If the starter kit is lost, you can reset the kit for that organization.

Download Starter-Kit:

  • Open AWS console and copy the Chef Server’s Public IP and hit it the same in a web browser.
  • Once you log into it, click on Organizations —> Create
  • Enter the Full Name, Short Name of the Organization and create.
  • Once the Organization is created, click on it and go to the Starter-Kit option which is on your left-hand side.
  • Click the Download Starter Kit and Proceed.
  • Once the Starter Kit downloaded, for your understanding unzip the Starter Kit, locate the knife.rb file and find the mentioned details.
  • You can also find your .PEM file, Cookbook and Role folders.

Bootstrap(ping):

This is a process that installs a chef-client on the targeted system so that it can run as a chef-client and communicate with the Chef Server. In simple terms, the process of adding a Node(s) to a Chef Server to communicate with it is called a Bootstrap or Bootstrapping. This can be done by…

  • Open Chef Work Station on your Local Machine, browse for the Starter Kit and make sure that you are in chef-repo
  • Now, run the following command to bootstrap the node which you already having in AWS ” knife bootstrap xxx.xxx.xxx.xxx -x user_name -i node_key -N node_name –sudo “
  • Where xxx denotes IP address of your Node machine, user_name is ubuntu (default for AWS Ubuntu Machines), node_key is the path for the node’s .PEM file, node_name is Node’s short name
  • When this is successful, you can find the complete details of the node like, node name (which you just mentioned while bootstrapping), Platform, FQDN, IP Address, Uptime, Last check-in in the web browser (Chef GUI) in the Nodes section.
  • In this method, you can add any number of nodes to a Chef Server in an Organization or across Organization.

Cookbook:

A Cookbook is a fundamental unit of configuration and policy distribution. A Cookbook defines a scenario and contains everything that is required to support that scenario

Create a Cookbook:

  • From your Chef Work Station, move to chef-repo
  • Create a cookbook using the following command “knife cookbook create cookbook_name”
  • Thus, a Cookbook is created in the chef-repo –> cookbook folder
  • Check the newly created Cookbook for its components.

Default.rb:

The default.rb file in recipes contain the ‘default’ recipe resources

  • From within your Cookbook folder navigate to the recipe folder using “cd recipe”
  • Open the default.rb and add the following command below, which will run system updates.
  • chef2
  • To test the recipe which you just written, upload the cookbook the Chef Server using the following command “knife cookbook upload cookbook_name”
  • We can check the Cookbook name from Chef GUI in Policies tab.
  • Now, add the recipe to the chosen node’s run list replacing node_name with your node’s name using the following command “knife node run_list add node_name “recipe[cookbook_name]””
  • Because this is a default recipe, the recipe name does not need to be defined after cookbook_name in the above code.
  • Access your chosen node and run the chef-client using the following command “chef-client” if you’re a root user or use “sudo chef- client”

How to:

  • Go to the AWS console and note the node’s IP address.
  • Using Putty, connect to the node with it’s .PPK file and IP address
  • After getting logged in, run the “sudo chef-client”
  • You can observe the update and upgrade runs.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s