Thanks for coming back for part 2 of my Chef Guide with Digital Ocean. In this part I will take you through setting up Chef with the Digital Ocean Gem and Bootstrapping your First VM. As a little bonus I will show you how to create a very simple cookbook to manage SSH Keys on your bootstrapped VM. If you have not already Done so remember to check out Part 1

The Digital Ocean Plugin

Setting Up the Plugin!

So now we have our chef server we should maybe put it to the test and bootstrap a new VM. To do this you will need to get the Digital Ocean plugin for knife.

This will install the Digital Ocean Gem. Once you have done that you will need to generate an API Access Token from your Digital Ocean API section. Just click Generate Token and Copy it to your clipboard. Navigate to your chef-repo/.chef folder and edit the knife.rb file we created in part 1. You will need to add your API Token to this file.

Make sure you replace the red text with your access token. Note all commands regarding Knife must be run from your chef-repo! Once you have completed this step you can test it my listing your Digital Ocean Droplets [Virtual Machine].

If you followed along from part 1 you should have at least 1 Droplet since this is your chef server!

Your First Cookbook!

So if we are going to bootstrap our VM we should have something to bootstrap it with. This will be added to our run list. we can use knife to create our new cookbook. We do this by using cookbook create with knife.

This has created some directories we do not need, so we can go ahead and delete those.

awesome now we can create our authorized_keys file. We create this in the files folder and it should be just as it appears on the server. If you don’t know how this should look please look it up as this is beyond the scope of this guide. I also recommend you add a comment explaining the file is chef managed so you can see changes. So on to the recipe. Inside the recipes folder we have a file called default.rb this is  where a little bit of Ruby or Scripting knowledge comes in handy. This is a really simple recipe.

So now we need to edit the metadata file. This just tells us a little information about the cookbook.

Now we just need to upload the cookbook to chef. We can do this 2 ways. By uploading all

uploading all every time can get a little slow so we can upload a single recipe too.

Awesome we can now bootstrap our new VM!

Creating and Bootstrapping a new Droplet

before going any further make sure to add an SSH public key to chef as this is required for the rest of this tutorial. Verify your SSH Key is there by running

If your SSH Key is there you can now proceed! So we need to find out a little about digital ocean before we can create our droplet. We should have our ssh key ID but we also need a Location ID, Image ID and Size ID. We can get this all from the Digital Ocean Knife Command. I will only be showing the lines of output I will be using.

Thats everything we need. I have highlighted the exact values we need in bold. So lets create and bootstrap our droplet!

Congratulations! You have now learned how to build your own Chef Server, Setup Your Workstation, Setup Digital Ocean Integration, Create a Simple Cookbook and Finally Bootstrap your new node! Now we are finished you can go ahead and destroy your droplet. Unless you desire to use it and you are more than welcome to do so.

And we are finished! To Learn More about Chef Check Out The Documentation : https://learn.chef.io Remember you can get $10 Digital Ocean Credit using my Link : https://www.digitalocean.com/?refcode=368a394500c1