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:
knife cookbook site download omnibus_updaterknife cookbook site download apache2knife cookbook site download aptknife cookbook site download build-essentialknife cookbook site download mongodbknife 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.
knife cookbook site download omnibus_updatertar xzvf omnibus_updater-0.0.5.tar.gz -C cookbooksknife 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.
knife cookbook site download mongodbknife cookbook site download apttar xzvf mongodb-0.11.0.tar.gz -C cookbookstar xzvf apt-1.5.0.tar.gz -C cookbooksknife cookbook upload aptknife 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.
export EDITOR=vim- knife uses theEDITORenvironment variable to determine which application to launch when you edit the node.- Add
"recipe[mongodb]"to therun_list - Run
chef-clienton the node using thevagrant provisioncommand.
We’ll follow the same steps to add passenger_apache2 to our run list.
knife cookbook site download passenger_apache2tar xzvf passenger_apache2-1.0.0.tar.gz -C cookbooksknife cookbook site download apache2tar xzvf apache2-1.3.2.tar.gz -C cookbooksknife cookbook upload apache2knife cookbook site download build-essentialtar xzvf build-essential-1.2.0.tar.gz -C cookbooksknife cookbook upload build-essentialknife 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 | |
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:
1 2 3 4 5 6 7 8 9 10 11 12 | |
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.