Skip to content

Instantly share code, notes, and snippets.

@botchagalupe
Created November 9, 2010 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save botchagalupe/669074 to your computer and use it in GitHub Desktop.
Save botchagalupe/669074 to your computer and use it in GitHub Desktop.
Chef FUD Lab 4 (Updated)

Chef Fundamentals Labs

Do first#

knife cookbook site vendor -d apache2

Lab 4 Create a Web Server cookbook

Exercise 1 - Create a new cookbook called webserver and launch new web servers on EC2

a. Create a new cookbook called webserver

Use knife cookbook --help to figure out how to create new cookbook. Also refer to the student guide for examples

b. Update the metadata.rb

Make sure you add a dependency (depends) for the apache2 cookbook. See http://wiki.opscode.com/display/chef/Cookbooks for details

The "depends" in the meta data does not ensure that the referenced cookbook is downloaded or uploaded to the Opscode platform

c. Update the the default.rb recipe in the ../cookbooks/webserver/recipes directory

#
# Cookbook Name:: webserver
# Recipe:: default
#
# Copyright 2010, Opscode, Inc..
#
# All rights reserved - Do Not Redistribute
#

include_recipe "apache2"

template "/var/www/index.html" do
  source "index.html.erb"
  owner "root"
  group "root"
  mode "0644"
end

This simple recipe will install Apache and create a default page that will updated in the template in the next step.

d. Create the default web page Template file

<html>
        <head>
                <title>Welcome to <%= node[:hostname]%></title>
        </head>
        <body>
                Chef rocks...you have reached:
                <ul>
                        <li><b>FQDN</b>: <%= node[:fqdn] %></li>
                        <li><b>Public FQDN</b>: <%= node[:ec2][:public_hostname]%></li>
                        <li><b>IP Address</b>: <%= node[:ipaddress] %></li>
                        <li><b>Public IP</b>: <%= node[:ec2][:public_ipv4] %></li>
                        <li><b>Platform</b>: <%= node[:platform] %></li>
                        <li><b>Plaform Version</b>: <%= node[:platform_version] %></li>
                        <li><b>Run List</b>: <%= node.run_list %></li>
                </ul>
        </body>
</html>

The name of the erb file should match the name of the template source name specified in the recipe. Create the file in ../templates/default directory.

e. Upload the new Webserver cookbook

knife cookbook upload -a

/* not needed ... knife cookbook upload webserver

Check to see if the new cookbook "webserver" is loaded by issuing the following commands.

knife cookbook list

knife cookbook show webserver

knife cookbook show webserver 0.0.1

knife cookbook show webserver latest recipes

Also makre sure the Apache2 cookbook is loaded

f. Create a new webserver.rb role file in ../chef-repo/roles

The new role file should include a description and a run_list that includes webserver recipe created in the previous step. See http://wiki.opscode.com/display/chef/Roles for examples.

g. Load the new webserver.rb role up to the Chef server

knife role from file webserver.rb 

h. Show the newly loaded role

knife role show webserver

__i. Bootstrap an existing EC2 instance with the Chef client

knife bootstrap <IP Address of the class assigned EC2 instance> --sudo -x ubuntu -Popstrain_0150 

Then assign a role and run the chef-client

knife node run_list add <Find the Ohai assigned node name> "role[webserver]"  

knife ssh "role:webserver" "sudo chef-client" -x ubuntu -Popstrain_0150 -a ec2.public_hostname

j. List your running instances and launch the web page using the following commands.

knife status --run-list

knife status "role:webserver" --run-list

curl <the public IP of the webserver instance>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment