Nathen Harvey

a blog

Learning Chef - Part 2

Learning Chef Series

  • Part 1 - Introduce the project, configure workstation, and register a node with hosted Chef
  • Part 2 - Download cookbooks from the community site, add MongoDB, Apache, and Passenger to our node
  • Part 3 - Start writing a cookbook to deploy our application
  • Part 4 - Finish the application deploy, introduce roles
  • Part 5 - Multi-node Vagrant
  • Part 6

Part 2 of our Learning Chef tutorial was run as a Google+ Hangout that was streamed to YouTube.

Review of Part 1

Discuss Chef Solo vs. Chef Server

Chef Solo allows you to run Chef Cookbooks without a Chef Server. There are a number of things that you don’t get when using Chef Solo. Check the Chef Solo page on the wiki for more information.

Download a number of cookbooks from the community site

Now that we’ve got our Vagrant instance connected to Chef Server we can start managing the configuration of the VM with Chef. We’ll download a number of cookbooks from the Community Site and extract them into our Chef repository.

Here are the commands we ran to download each cookbook:

  1. knife cookbook site download omnibus_updater
  2. knife cookbook site download apache2
  3. knife cookbook site download apt
  4. knife cookbook site download build-essential
  5. knife cookbook site download mongodb
  6. knife cookbook site download passenger_apache2

After downloading each cookbook, extract it to the cookbooks directory of the chef-repo:

tar xzvf COOKBOOK_NAME.tar.gz -C cookbooks

Finally, upload each cookbook to the Hosted Chef server:

knife cookbook upload COOKBOOK_NAME

This video shows the process for grabbing the omnibus_updater cookbook off of the community site.

  1. knife cookbook site download omnibus_updater
  2. tar xzvf omnibus_updater-0.0.5.tar.gz -C cookbooks
  3. knife cookbook upload omnibus_updater

This video shows the process for grabbing the mongodb cookbook, and it’s dependency, the apt cookbook, off of the community site.

  1. knife cookbook site download mongodb
  2. knife cookbook site download apt
  3. tar xzvf mongodb-0.11.0.tar.gz -C cookbooks
  4. tar xzvf apt-1.5.0.tar.gz -C cookbooks
  5. knife cookbook upload apt
  6. knife cookbook upload mongodb

Update the run list for our node

There are a number of ways to update a node’s run list. You can do so in a web browser while logged in to Hosted Chef or you can do so using knife.

In our session, we first used the Opscode Chef management interface.

You can also update your node’s run list using knife. In this video, we’ll use knife to add mongodb to the node’s run list.

  1. export EDITOR=vim - knife uses the EDITOR environment variable to determine which application to launch when you edit the node.
  2. Add "recipe[mongodb]" to the run_list
  3. Run chef-client on the node using the vagrant provision command.

We’ll follow the same steps to add passenger_apache2 to our run list.

  1. knife cookbook site download passenger_apache2
  2. tar xzvf passenger_apache2-1.0.0.tar.gz -C cookbooks
  3. knife cookbook site download apache2
  4. tar xzvf apache2-1.3.2.tar.gz -C cookbooks
  5. knife cookbook upload apache2
  6. knife cookbook site download build-essential
  7. tar xzvf build-essential-1.2.0.tar.gz -C cookbooks
  8. knife cookbook upload build-essential
  9. knife cookbook upload passenger_apache2

We will then add passenger_apache2 to the run list using knife node edit patrick_vm. When we run vagrant provision, we’ll hit an error that requires us to add apt to the run list prior to passenger_apache2.

By the end of this video, the run list should look like:

1
2
3
4
5
6
"run_list" : [
    "recipe[apt]",
    "recipe[omnibus_updater]",
    "recipe[mongodb]",
    "recipe[passenger_apache2]"
]

Add port forwarding to the Vagrant instance

Finally, we updated the Vagrant configuration so that port 80 on the VM is forwarded to port 8080. This was done by adding config.vm.forward_port 80, 8080 to our Vagrantfile. Here’s the full Vagrantfile:

Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
Vagrant::Config.run do |config|
  config.vm.box = "opscode-ubuntu-12.04"
  config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box"
  config.vm.forward_port 80, 8080

  config.vm.provision :chef_client do |chef|
    chef.chef_server_url = "https://api.opscode.com/organizations/fidor"
    chef.validation_key_path = "./.chef/fidor-validator.pem"
    chef.validation_client_name = "fidor-validator"
    chef.node_name = "patrick_vm"
  end
end

Summarizing Part 2

We now have the following in place:

  • A node managed by Chef - our Vagrant VM
  • The latest version of Chef (10.16.2) is running on the node
  • Six cookbooks added to our local workstation
  • Six cookbooks added to our Hosted Chef organization
  • The run list for our node was updated
  • The node has a working MongoDB database running
  • The node has Apache and Passenger running
  • Port Forwarding is configured on the Vagrant VM

What’s Next

In Learning Chef - Part 3 we install some more cookbooks and start writing our own cookbook to deploy a sample Rails application.

In the meantime, please let us know what you think of this post and these videos! Drop a note in the comments or reach out to @nathenharvey or @mulpat on twitter.

Comments