One of the best things that came out of using EngineYard Cloud was learning about Chef. Chef has changed my world when it comes to managing servers, and I now wouldn't do any amount of system administration without the kind of automation and scriptability Chef provides. Here are a couple of tips on the reasons for and the benefits of using Chef.
Tip #1: Chef keeps you honest
Yesterday I was reminded just how useful Chef can be when I updated the wordpress layout on a client's server just by running ./config/chef/runchef.rb from my project folder. Not only did the files I changed get pushed out (as you would expect), but I also saw a note in the output about a config file changing. Curious about the unintended change, I did a diff of the just-updated config file with the backup file created by Chef. The diff reminded me that I had made an emergency manual change on the server that I hadn't yet added to my Chef config (bad me). Since Chef told me about the change to the file, and gave me the location of the backup it made just before changing the file, it was easy for me to find the differences and add them to my build templates (and commit them to my git repo).
Tip #2: Use Vagrant for Chef recipe development
Recently I started working on a new slice configuration since I need to move slices away from slicehost. Since Linux distributions and software packages are always being updated (like Debian 6 and Passenger 3.0.7), I like to start with my stock set of Chef scripts and update them for those kinds of changes. I'll start with a clean installation of a Linux distro, and fold in my recipes one by one, making sure each is using the best method of installation and configuration. Vagrant is a great tool for this kind of development for a few reasons:
- It's free: You aren't spinning up an instance at EC2 or Rackspace Cloud to get a clean starting point.
- It's quick: Again, you aren't depending on EC2 or RS load times, and bandwidth isn't a problem.
- Local filesystem: If you want to start a Chef template from, say, a package-installed config file like /etc/ssh/sshd_config, all you have to do is
cp /etc/ssh/sshd_config /vagrant/cookbooks/ssh/templates/default/sshd_config.erbsince Vagrant mounts your current working dir to /vagrant on the virtual machine.
Even if you aren't managing a farm full of servers, Chef is still fantastic to use. I use chef-solo to manage all the servers for my clients, and it makes it easy to have repeatable, predictable deployments for all of them. If you haven't used it yet, do grab Vagrant and give it a shot.