One-Step Chef via Cato

In a previous post, I walked through using AWS CloudFormation and a user data script to spin up a vanilla Ubuntu instance, install Chef, and direct Chef to create a WordPress server. Once you get the hang of it, CloudFormation templates, user data scripts and bootstrapping start to become ‘easy’, but there’s no denying this sort of thing isn’t for the casual observer.

Cato, Cloud Sidekick’s automation platform, strives to shield the already overworked SA from any unnecessary complexity. Cato’s drag-and-drop task editor is a refreshing change from staring all day at a console. Besides, if you’re like me, for every three keys I press, one is backspace!

So, let’s take a look at how easy it is to create a WordPress server using a Cato Task. Believe it or not, I’m gonna do this in one step. You heard me … one step.

Here’s a screenshot of the single Cato command we execute to spin up an EC2 instance.

As you can see, all the important values are populated: the AMI image id, the Security Group, a KeyPair, and the instance type.

So, this simple command will start up a new Ubuntu image in the us-east-1 region. Where’s the rest? It’s in the User Data field.

The User Data Field
#!/bin/bash
set -e -x
export DEBIAN_FRONTEND=noninteractive

# tell apt-get about the opscode package repository
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list

#get the opscode keys
mkdir -p /etc/apt/trusted.gpg.d
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
gpg --export packages@opscode.com | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null

# update the apt library with the current versions
apt-get --yes --quiet update

# install the opscode key permanently
apt-get install opscode-keyring

# install Chef (the echo part passes in a few required variables, otherwise the chef installer prompts the user.)
echo "chef chef/chef_server_url string none" | debconf-set-selections && apt-get install chef -y

# install 'git' (required to get the cookbook repository)
apt-get --yes --quiet install git-core

# checkout the Opscode cookbook repository.
cd /var
git clone git://github.com/opscode/chef-repo.git

# use the chef 'knife' utility to grab the cookbook(s) we want
sudo knife cookbook site install wordpress --cookbook-path /var/chef-repo/cookbooks

# create the minimal config file needed for chef solo
echo -e 'file_cache_path "/var/chef-repo"\ncookbook_path "/var/chef-repo/cookbooks"' | tee /etc/chef/solo.rb

# create the 'node' config file (tells Chef what cookbooks to apply to 'me')
# note: the cookbooks themselves will look for these config settings.
echo -e '{
"wordpress": {
"db": {
"database": "wordpress",
"user": "admin",
"password": "admin",
"host": "localhost"
}
},
"run_list": ["recipe[wordpress]"]
}' | tee /etc/chef/node.json

# kick off chef-solo
sudo chef-solo -j /etc/chef/node.json

# create a 'done' file so other scripts can know we're all finished.
touch /home/ubuntu/complete

User Data is Amazon’s boilerplate mechanism for bootstrapping an image. It’s basically just a series of commands that get executed once the server is up and running.

Of course this is a simple example, but it doesn’t take much to make it very powerful. A one line task like this would probably be run in an automated manner, for example after another task determines more capacity is needed.

Also, if it were me I probably wouldn’t even bother with the user data. Once the instance is up and running, Cato can interact with it without needing an agent, executing each of those commands individually, with full logging of each command available in the Cato UI. Yep, that means you can troubleshoot without having to open an ssh session and dig around /var/log looking for errors.

Cato will email you, and can even send a Tweet if your Task has issues. Just a few of the many things you can easily do with Cato!

Sorry, comments are closed for this post.