Project Setup
One of the goals of this guide is to create a “setup” project that you can share among your development team. This project can be checked into/out of git and will we be preconfigured to interact with VirtualBox locally, all of your chef cookbooks locally, OpCode servers upstream, and servers in the cloud using RackCloud.
Project Directory / Git Repository
First, let’s create a directory, make it use our new ruby, and make it a git repository. Open Terminal from your Applications folder and do the following:
1 $ cd ~
2 $ mkdir devops_toolbox
3 $ echo "rvm 1.9.3@devops_toolbox --create" > devops_toolbox/.rvmrc
4 $ cd devops_toolbox
5 $ git init .
6 Initialized empty Git repository in /Users/claco/devops_toolbox/.git/
From the top: Line 1 changes to your home directory. Line 2 creates the new project folder. Line 3 creates an
.rvmrc
file to tell RVM what ruby to use when we enter this folder. Line 4 enters the new project directory, and Line 5 creates a new git repository out of that directory.
When RVM encounters an .rvmrc
it doesn’t know for the first time, it will present a prompt asking if you want to load/trust it. Say yes!
1 ====================================================================================
2 = NOTICE =
3 ====================================================================================
4 = RVM has encountered a new or modified .rvmrc file in the current directory =
5 = This is a shell script and therefore may contain any shell commands. =
6 = =
7 = Examine the contents of this file carefully to be sure the contents are =
8 = safe before trusting it! ( Choose v[iew] below to view the contents ) =
9 ====================================================================================
10 Do you wish to trust this .rvmrc file? (/Users/claco/devops_toolbox/.rvmrc)
11 y[es], n[o], v[iew], c[ancel]> y
12 Using /Users/claco/.rvm/gems/ruby-1.9.3-p194 with gemset devops_toolbox
13 Running /Users/claco/.rvm/hooks/after_use
14 Running /Users/claco/.rvm/hooks/after_cd
Just for giggles, let’s makes sure we’re now using the new Ruby we installed earlier. Type the following command and hit RETURN
1 $ rvm current
2 ruby-1.9.3-p125@devops_toolbox
The @devops_toolbox
is an RVM “gem set”. Think of it as just a named bucket where all of the gems we install later will go into. You can create buckets for different projects, keeping things nice and tidy and separated from each other.
Vagrant/Veewee Directories
Next, let’s make our Vagrant/Veewee related directories inside of the devops_toolbox
folder buy running these commands:
1 $ mkdir boxes; touch boxes/.gitkeep
2 $ mkdir definitions; touch definitions/.gitkeep
3 $ mkdir instances; touch instances/.gitkeep
4 $ mkdir iso; touch iso/.gitkeep
From the top: The
boxes
folder is where we’ll store boxesveewee
has created. Thedefinitions
folder is whereveewee
will store local box definitions. Theinstances
folder is where we’ll storevagrant
configurations for specific instances of our boxes, andiso
is where veewee will download ISO install discs to when creating new boxes. More on that later.
You may be wondering what the touch .gitkeep
is all about. That tells git to keep a folder in source control even if it is empty.
OpsCode Chef/Knife Directories
Next, we’ll create the directories related to using OpsCode Chef locally/hosted including our credentials and cookbooks.
1 $ mkdir .chef; touch .chef/.gitkeep
2 $ mkdir -p chef/cookbooks; touch chef/cookbooks/.gitkeep
3 $ mkdir -p chef/data_bags; touch chef/data_bags/.gitkeep
4 $ mkdir -p chef/environments; touch chef/environments/.gitkeep
5 $ mkdir -p chef/roles; touch chef/roles/.gitkeep
From the top: The
.chef
directory will contain the configuration and credentials it useknife
, the command line interface for Chef/OpsCode. Thechef
directory will contain local copies of our cookbooks, data bags, environments, and roles. More on that later as well. :-)
And for comparison, here’s the directory structure you should have now: (If you don’t have tree installed, try brew install tree
)
1 $ tree
2 .
3 ├── .chef
4 ├── boxes
5 ├── chef
6 │ ├── cookbooks
7 │ ├── data_bags
8 │ ├── environments
9 │ └── roles
10 ├── definitions
11 ├── instances
12 └── iso
Commit Our Work
If you don’t want to commit your boxes or iso images to git for size/time/network speed reason, let’s add them to the .gitignore
file:
1 $ echo "*.iso" >> .gitignore
2 $ echo "*.box" >> .gitignore
Then we can commit our work to the git repository:
1 $ git add .
2 $ git commit -m "Initial Commit"
3 [master (root-commit) 8ada8b3] Initial Commit
4 2 files changed, 3 insertions(+)
5 create mode 100644 .chef/.gitkeep
6 create mode 100644 .gitignore
7 create mode 100644 .rvmrc
8 create mode 100644 boxes/.gitkeep
9 create mode 100644 chef/cookbooks/.gitkeep
10 create mode 100644 chef/data_bags/.gitkeep
11 create mode 100644 chef/environments/.gitkeep
12 create mode 100644 chef/roles/.gitkeep
13 create mode 100644 definitions/.gitkeep
14 create mode 100644 instances/.gitkeep
15 create mode 100644 iso/.gitkeep
To Continue…
- Introduction – Introduction
- Installing Prerequisites – XCode, CommandLineTools, Homebrew, RVM, Ruby, and VirtualBox
- Project Setup – Create the git repository and directory structure for Vagrant, Chef, etc.
- Vagrant/Veewee Installation – Install Vagrant/Vewee to create/control VirtualBox machines
- Define/Create a Vagrant Box – Define and Create a Vagrant Box for use i VirtualBox
- Provisioning Machines with Vagrant – Provision a cluster (Web/DB) of machines using Vagrant
- Configuring Machines Using Chef Solo – Configuring our new machine instances using Chef Solo
- Customizing Recipes for Our Application – Customize the recipes we have to prepare for our application deployment
- Create and Deploy a Rails Applications – Create a simple Rails application and deploy it to our Vagrant instances
- Migrate from Chef Solo to Hosted Chef – Migrate from using Chef Solo to hosted Chef at OpsCode
- Migrate Servers to RackCloud – Migrate your servers from VirtualBox to “The Cloud” using Rackspace.