Boom

Difficult takes a day, impossible takes a week.

Installing a RapidSSL SSL Cert on an AWS Load Balancer

Over at CodePen it came time to renew our SSL cert. I dutifully follwed the setup instructions, but I was greeted with this error:

Invalid Public Key Certificate

After talking with the support staff at RapidSSL, I was told to reverse the Intermediate CA Bundle. The example from their instructions looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-----BEGIN CERTIFICATE----
Primary Intermediate CA
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
Secondary Intermediate CA
-----END CERTIFICATE-----

Needs to be switched to..

-----BEGIN CERTIFICATE-----
Secondary Intermediate CA
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
Primary Intermediate CA
-----END CERTIFICATE-----

I’m noting this here so in 2016 when we have to renew our SSL Cert, we’ll know what to do.

Set Up a Static Host-Only Network for Virtualbox

Intro

Setting up a Host-Only Network with Ubuntu Server requires some knowledge of networking. But why accumulate knowledge when you can simply copy snippets from the internet?

Set Up Host-Only Networking

Host-Only Networking is a setting in VirtualBox that allows your host machine to act like a DHCP server for a private network on your machine. Using this setting, you may loom like a god above the private network you create on your garden of nodes. Or, you can just test out some new service… Your choice.

Enable Host-Only Networking

Right-click settings on your virtual machine of choice, then click the Network tab. Choose Adapter 2 and then click Enable Network Adapter. Make sure the Name dropdown says vboxnet1. If it does not, click VirtualBox from your menu bar, then Preferences, and then the Network tab because we’re going to add a new network. Click the Add host-only network button. This will create a new Host-Only network with a gateway of 33.33.33.1. We’ll set our Ubuntu Server up accordingly.

Configure Your Ubuntu Box

Start the box, then issue the following commands:

sudo vi /etc/network/interfaces

Then, make your interfaces file look like this:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
    address 33.33.33.11
    netmask 255.255.255.0
    gateway 33.33.33.1

Then, reboot your machine.

sudo reboot

Verify Your Settings

We want to make sure that the settings you put in place work. To do so, issue this command

ifconfig

And view the resulting settings:

eth0      Link encap:Ethernet  HWaddr 08:00:27:c8:d3:98  
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
        ...Truncated for brevity...

eth1      Link encap:Ethernet  HWaddr 08:00:27:0e:e2:c0  
       inet addr:33.33.33.11  Bcast:0.0.0.0  Mask:255.255.255.0
        ...Truncated for brevity...

If you don’t see that, be sure that the Host Only Network you created in the steps above is in the 33.33.33.1 gateway range.

Reading More

Ubuntu Network Configuration Accessing Ubuntu Server in a VirtualBox Virtual Machine

How to Manage Your Dotfiles With Git

Update

The blog post below is over-simplified. You should follow the steps outlined by the vimcast guys.

Objective

Programs like vim, bash, and zsh all use dotfiles for configuration. You want to back them up in case of disaster. Here’s how I handle that using a .dotfiles directory and symlinks.

Where Do My dotfiles Live?

By default vim, bash, zsh and other programs store dotfiles in your home directory. You can view the dotfiles in your home directory like so:

cd
ls -al

Vim As An Example

In the following steps, you’ll learn how to back up your Vim configuration to a directory named .dotfiles.

To get started, create your .dotfiles directory.

cd
mkdir -p .dotfiles/vim

Note: The -p option tells bash to create the directory recursively, building the entire path if it does not exist.

Now, move your .vim and .vimrc files to your .dotfiles directory.

mv .vimrc .vim .dotfiles/vim

Finally, symlink the files and folders you just moved back to their original location.

cd
ln -s .dotfiles/vim/.vimrc .vimrc
ln -s .dotfiles/vim/.vim .vim

Back It Up

Remember to use whatever source control system you like to back up your .dotfiles directory. I prefer git.

cd ~/.dotfiles
git init
git add .
git commit -a -m 'My first dotfile commit'

Chef Recipe to Upgrade Virtualbox Additions

Every time the guys at VirtualBox update their software, you have to scramble to find resources to upgrade your virtualbox guest additions. You also get the following annoying message.

[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

To prevent this from being a hassle, I created this chef recipe to help ease our suffering.

You will probably have to restart your vagrant box for this to work. I’m not 100% sure.

Command-Line Resources

SSH Tips

This excellent article entitled Tips for Remote Unix Work covers some vital SSH goodness. For example, copying your public ssh key

ssh user@example.com 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

and piping commands via SSH without logging into the remote machine

cd && tar czv src | ssh example.com 'tar xz'

How to Test Out a Shared Vagrant Box

Intro

At some point, someone will offer to share a vagrant box with you. These are the steps required to get that box working.

Create a Working Folder

We’ll need a place to house the .box file and a way to start it up, so create the directory and use the vagrant gem’s init call, which will make a VagrantFile for you.

mkdir WorkingFolder
cd WorkingFolder
vagrant init

Download the .box File

Put the .box file into your Working Directory. For this exercise, we’ll call it sharedBox.box.

Add The Box to Vagrant’s Box Cache

The command below will import your .box file.

cd WorkingFolder
vagrant box add shared_box sharedBox.box

Importing a box file will copy it your ~/.vagrant.d/boxes folder. To prove this, run the ls command.

ls ~/.vagrant.d/boxes
yourshell$ shared_box

Notice that the shared_box argument to the box add command produces a shared_box file in your ~/.vagrant.d/boxes directory. Now, when dealing with this box in vagrant, you’ll refer to it as shared_box. So, you can safely delete the sharedBox.box file from your Working Directory.

rm sharedBox.box

Edit the VagrantFile

In order start the vagrant box, you’ll need to reference it in your VagrantFile. Using your editor, change

config.vm.box = "base"

to

config.vm.box = "shared_box"

Now when you tell vagrant to start, you’ll be referring to the shared_box.

All Done

With these steps in place, you’re ready to start vagrant with the vagrant_up command.

Setting Up a Vagrant Development Environment

Install the Vagrant gem

You need vagrant installed for this process to work. Vagrant depends on a version of ruby we’ll set up using the Ruby Version Manager, as shown below. This can take a while, so be patient. A quick note for mac developers: RVM installs Ruby from source. In order to do so, you will need Xcode installed. You can try using another gcc, but for one-stop goodness, install Xcode and move along.

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source ~/.bash_profile
rvm install 1.9.2
rvm use 1.9.2 --default

Next install vagrant

gem install vagrant

Create A Home Base

It is likely you’ll be creating several vagrant boxes (individual machines) as you move along, so it makes sense to keep them organized in one place. Let’s create that now.

mkdir ~/boxes

The boxes name given above is just my convention. You may name that folder anything you like. We’ll refer to this as your boxes directory.

Clone The Opscode Cookbooks

Opscode has a set of cookbooks you’ll use when writing chef scripts. You’ll want to pull these down and keep them within reach.

cd ~/boxes
git clone https://github.com/opscode/cookbooks.git

This will create a directory cookbooks in your base directory containing all of Opscode’s great cookbooks. I suggest deleting the .git folder at the base of this dir and checking your cookbooks into your own source control repo. As you add write cookbooks of your own, you may save them there.

Create A Project Directory

A project directory represents one (or more) VMs associated by a VagrantFile. You’ll learn more about the VagrantFile later in this article. For now, just know that the VagrantFile acts as the configuration for your Vagrant project. In the snippet below, we’ll create a project directory called ProjectDirectory. Choose a name that properly describes the box you’re building. For example, WebServer would be a good Project Directory name.

cd ~/boxes/
mkdir ProjectDirectory
cd ProjectDirectory

Clone the Chef Repo

The Chef Repo is the basic structure required by Chef. Your cookbooks and other important files will be kept here. In the example below, we’ll be turning your Project Directory into a Chef Repo. That’s why we add the . at the end of the git clone command.

cd ~/boxes/ProjectDirectory
git clone https://github.com/opscode/chef-repo.git .

If you run a ls -al command, you’ll notice the following directory structure in your Project Directory now:

ls -al
total 32
drwxr-xr-x  13 timsabat  staff   442 Dec 13 12:36 .
drwxr-xr-x   7 timsabat  staff   238 Dec 13 12:36 ..
drwxr-xr-x  13 timsabat  staff   442 Dec 13 12:36 .git
-rw-r--r--   1 timsabat  staff    18 Dec 13 12:36 .gitignore
-rw-r--r--   1 timsabat  staff  3521 Dec 13 12:36 README.md
-rw-r--r--   1 timsabat  staff  2171 Dec 13 12:36 Rakefile
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 certificates
-rw-r--r--   1 timsabat  staff   156 Dec 13 12:36 chefignore
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 config
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 cookbooks
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 data_bags
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 environments
drwxr-xr-x   3 timsabat  staff   102 Dec 13 12:36 roles

Since we’ll be creating our own git repository in this directory, let’s delete the one provided by the previous clone command.

cd ~/boxes/ProjectDirectory
sudo rm -r .git .gitignore

Initialize your Vagrant environment

Vagrant depends on a file called VagrantFile for configuration information. The following command creates that file.

vagrant init

The ls command will prove the vagrant init call did create your VagrantFile.

Now we’ll create a knife.rb file to control how chef’s knife command interacts with your project.

cd ~/boxes/ProjectDirectory
mkdir .chef
touch .chef/knife.rb

What is knife you ask? Opscode describes this way:

[knife] is used by administrators to interact with the Chef Server API and the local Chef repository. It provides the capability to manipulate nodes, cookbooks, roles, databags, environments, etc., and can also be used to provision cloud resources and to bootstrap systems.

The following values should be present in your knife.rb file.

current_dir = File.dirname(__FILE__)
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path            ["#{current_dir}/../cookbooks", "#{current_dir}/../site-cookbooks"]

The options you’ve set here tell chef where to create new cookbooks, and how/where to cache your erb templates.

Create your vagrant_main cookbook

In order for vagrant to configure your virtual machine, you must tell it which Chef cookbook to run first. For convention’s sake, we’ll call this cookbook vagrant_main. If you were using hosted Chef instead of chef-solo (Vagrant’s default mode), the would represent the ‘run list’. If you don’t know what that means, no big deal, you don’t have to understand hosted chef to run Vagrant.

We’ll run the following knife command create your vagrant_main cookbook.

cd ~/boxes/ProjectDirectory
knife cookbook create vagrant_main

Observe your handiwork :

cd ~/boxes/ProjectDirectory/cookbooks/vagrant_main
ls -al

and you’ll see output which looks like this:

-rw-r--r--   1 timsabat  staff   88 Dec 14 08:56 README.md
drwxr-xr-x   2 timsabat  staff   68 Dec 14 08:56 attributes
drwxr-xr-x   2 timsabat  staff   68 Dec 14 08:56 definitions
drwxr-xr-x   3 timsabat  staff  102 Dec 14 08:56 files
drwxr-xr-x   2 timsabat  staff   68 Dec 14 08:56 libraries
-rw-r--r--   1 timsabat  staff  249 Dec 14 08:56 metadata.rb
drwxr-xr-x   2 timsabat  staff   68 Dec 14 08:56 providers
drwxr-xr-x   3 timsabat  staff  102 Dec 14 08:56 recipes
drwxr-xr-x   2 timsabat  staff   68 Dec 14 08:56 resources
drwxr-xr-x   3 timsabat  staff  102 Dec 14 08:56 templates

Each directory here has special meaning to Chef. You and read about what each means by checking out the Opscode cookbook documentation.

Finally, we’ll tell the VagrantFile to run Chef against the vagrant_main cookbook we just created. To do so, open the VagrantFile and change the values

# config.vm.provision :chef_solo do |chef|
#   chef.cookbooks_path = "cookbooks"
#   chef.add_recipe "mysql"
#   chef.add_role "web"
#
#   # You may also specify custom JSON attributes:
#   chef.json = { :mysql_password => "foo" }
# end

to

config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
    chef.add_recipe "vagrant_main"
end

Conclusion

You’ve set up a Vagrant Development Environment. Now, write a recipe.

Installing Chef Client and Chef Server

This guide will get you up and running with chef server and client on the same Windows 2008 Server.

The instructions outlined herin are a distillaiton of the Chef Fast-Start Guide For Windows

Create a Hosted Chef Account

The instructions for Creating a Hosted Chef Account are easy to follow. Do that and return to this guide.

Install Chef Client and Server

Run the Chef Full Installer and then verify your install with these commands.

chef-client --version
tar --version

should produce

Chef: 0.10.4
bsdtar 2.8.3 0 libarchive 2.8.3

Install Git

Follow the instructions listed in the github.com Windows Setup Guide.

Then verify

git --version

will produce

git version 1.7.6.mmsygit.0

or whatever the latest git version happens to be.

Prepare Your File System

Follow these instructions to set up your base Chef directory. You’ll use this when creating cookbooks.

cd %HOMEPATH%
git clone git://github.com/opscode/chef-repo.git
mkdir %HOMEPATH%\chef-repo\.chef

Move in your Chef keys you created in the first step of this guide titled Create A Hosted Account. Edit the snippet below for your system settings:

move %HOMEPATH%\Downloads\knife.rb %HOMEPATH%\chef-repo\.chef
move %HOMEPATH%\Downloads\tsabat.pem %HOMEPATH%\chef-repo\.chef
move %HOMEPATH%\Downloads\fizbuzz-validator.pem %HOMEPATH%\chef-repo\.chef

Open WordPad to edit your knife.rb file.

Write %HOMEPATH%\chef-repo\.chef\knife.rb, 

MEPATH%\chef-repo In that file, change cookbook_path ["#{current_dir}/../cookbooks"] to cookbook_path ["#{ENV['HOME']}/chef-repo/cookbooks"]

Verify Connection To Hosted Chef

Run the commands

cd %HOMEPATH%\chef-repo
knife client list fizbuzz-validator

TODO: Explain the validator’s role in Chef

and you’ll see your machine name listed there.

Configure The Workstation as Client

Run these commands

cd %HOMEPATH%\chef-repo
knife configure client %HOMEPATH%\chef-repo

Then edit your client.rb

Write %HOMEPATH%\chef-repo

making it look like this, substituting fizbuzz for your own organization.

log_level        :info
log_location     STDOUT
chef_server_url  'https://api.opscode.com/organizations/fizbuzz'
validation_client_name 'fizbuzz-validator'
validation_key cd "#{ENV['HOME']}/chef-repo/.chef/fizbuzz-validator.pem"
client_key "#{ENV['home']}/chef-repo/client.pem 

Run chef-client to register your client with the server.

chef-client -c %HOMEPATH%\chef-repo\client.rb

You’ll see output which looks like this:

[Mon, 12 Dec 2011 00:48:03 -0800] INFO: *** Chef 0.10.4 ***
[Mon, 12 Dec 2011 00:48:09 -0800] INFO: Client key C:\Users\Administrator/chef-r
epo/client.pem is not present - registering
[Mon, 12 Dec 2011 00:48:14 -0800] INFO: Run List is []
[Mon, 12 Dec 2011 00:48:14 -0800] INFO: Run List expands to []
[Mon, 12 Dec 2011 00:48:14 -0800] INFO: Starting Chef Run for WIN-JLR7H2GM3Q5
[Mon, 12 Dec 2011 00:48:14 -0800] INFO: Loading cookbooks []
[Mon, 12 Dec 2011 00:48:14 -0800] WARN: Node WIN-JLR7H2GM3Q5 has an empty run li
st.
[Mon, 12 Dec 2011 00:48:15 -0800] INFO: Chef Run complete in 1.484375 seconds
[Mon, 12 Dec 2011 00:48:15 -0800] INFO: Running report handlers
[Mon, 12 Dec 2011 00:48:15 -0800] INFO: Report handlers complete

Verify that your node was added

cd %HOMEPATH%\chef-repo
knife client list

Vagrant Boxes and Veewee

11PM Thursday Night

I’ve been trying to get Windows 2008 vagrant box up and running and I’ve had little luck. According to instructions on ducea.com, the creation of a base windows box sould be a breeze using the veewee gem, but the postinstall.sh script placed in the base of the cygwin install had several errors.

10AM Friday Morning

It looks like cygwin was sporting an older version.

TODO:

  1. Edit the postinstall.sh file to pull the latest cygwin files.
  2. Also, the ruby installer looks like it wants to pull the 32 bit install. Is that right?