Skip to content

Instantly share code, notes, and snippets.

@metaxis
Forked from botchagalupe/gist:670599
Created December 8, 2010 02:06
Show Gist options
  • Save metaxis/732787 to your computer and use it in GitHub Desktop.
Save metaxis/732787 to your computer and use it in GitHub Desktop.
knife lab

Chef Fundamentals Labs

Knife lab

Knife Fu

Exercise 1 - Getting familiar with the knife command

__ Issue the following commands and understand the output.__

help exploration

shows common flags and all subcommands

knife --help

show contextual help for node subcommands

knife node --help

status of our infrastructure

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

explore node commands

knife node list
knife node show <supply an instance id for the for the lb instance>
knife node show <supply an instance id for the for the lb instance> --run-list

Install gem-man to use the knife man pages

sudo gem install gem-man 

Issue the gem man page for Chef

gem man chef

Use knife

Check to see if the new cookbook "webserver" is loaded.

knife cookbook list

Inspect the contents of the cookbook using "cookbook show" subcommands.

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

knife status --run-list

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

curl <the public IP of the webserver instance>

__ Search for a copy of the haproxy cookbook by issuing the following commands.__

 knife cookbook site search haproxy

 knife cookbook site show haproxy

__ Download a copy of the haproxy cookbook.__

 knife cookbook site vendor -d haproxy

See ( http://wiki.opscode.com/display/chef/Chef+Repository#ChefRepository-cookbooks ) for an explanation of the vendor branch pattern used in this command.

__ Find the metadata.rb and list the supported OS's for this cookbook__

__ Upload cookbook __

knife cookbook upload haproxy

__ Create a LB role we will use tomorrow__

create a lb role

$EDITOR roles/lb.rb 

name "lb"
description "load balancer"
override_attributes(
)
run_list(
  "recipe[haproxy]"
)

__ Load the new lb.rb role up to the Chef server__

knife role from file lb.rb 

__ Show the newly loaded role__

knife role show lb

let's issue some commands "in parallel" using knife ssh

knife ssh "*:*" "sudo chef-client" -x ubuntu -a ec2.public_hostname

uptime

knife ssh "*:*" "uptime" -x ubuntu -a ec2.public_hostname

Exercise 2 - Using knife to bootstrap an already running instance

__ Ask Aaron for a new ec2 instance, I'll give you the hostname __

save the RSA private key to ~/.ssh/aaron:

(copy key from skype)

cat > ~/.ssh/aaron

(right-click in PuTTY to paste) (hit enter) (Control-D to end)

knife bootstrap <new server> -i ~/.ssh/aaron --sudo -x ubuntu -r 'runlist'

__ Verify the status of the bootstrapped instance.__

knife status --run-list

__ Add a role to the new instances run_list.__

knife node run_list add NODENAME "role[lb]"

Use the node name displayed in the first field of the "knife status". Notice the default name of the bootstrapped node is not the instance id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment