2012-03-16

Long post now shorter

I had a long post about the tribulations of installing Ubuntu on a local server and then getting virtual box.  However a combination of Windows update and Windows live writer managed to edit it down to nothing so I am starting again.

Installing the OS, OpenSSH, virtual box and Vagrant

I used Ubuntu 32 bit 11.10 (as I needed RubyGems >= 1.3.6) to install virtual box and vagrant.  I should have selected OpenSSH as a default package (I selected nothing) so had to install that later:

sudo apt-get install openssh-server openssh-client

In order to login with out a username and password I wanted to used the SSH public key.  I modified the network interfaces to change the IP adresss and after a reboot changed the SSH control file to read the atuhorisation file.  Then added the authorisation key to the public key from that generated by Putty.  Note you have to edit the framework and end of lines, see here.

Another lifesaver which slowed me down all afternoon:

--disable-known-hosts stops Fabric from getting confused when you generate the same VM repeatedly”

Vagrant up for the first time

The aim here is to get the first box so that I can power it up and down – then aim to make that happen using fabric.  I thought I might have to this several times so firstly I decided to download the box to my local webserver from opscode and then install from there.

 vagrant box add lucid32 http://files.mysite.net/ubuntu10.04-gems.box

That turned out to be a good plan as the update then only took a few seconds. Then to start the machine and vagrant up:

mkdir devbox32
cd devbox32
vagrant init lucid32
vagrant up



The machine paused and after some messages I had a new machine in about 2min.



I can login to it either using putty from my machine or:




vagrant ssh




vagrant ssh from the host machine.  The username and password were vagrant.  Then I shut it down with:




vagrant halt

vagrant destroy -f




You don’t need the halt but it is a bit cleaner.  Next time you start up you don’t need to download the box.  The vagrant up command is now in fabric.  The complete code is in the appendix 1, here is the guts of it and the command lines:




def uat_up():

run('cd uatbox32 && vagrant up')




and the command line on my windows development box is :




fab --disable-known-hosts base uat_up




and I can login with Putty.



Appendix 1 Initial fabric file to do vagrant up remotely


Complete fabfile.py to get you started you will need to edit the me to your user:




import os.path

import subprocess



from  fabric.api import *

from fabric.contrib.console import confirm



# Constants

KEY_DIR = r'C:\Users\me\Library\keys'


PUTTY_DIR = r'C:\Program Files (x86)\PuTTY'



# These private python functions do not get exposed on the command line via the

# 'fab' tool. They will not show up when the user runs 'fab --list'


def _start_pageant_and_store_key(keyfile_name):


    """


    Starts the Pageant key agent, and loads the private key in to it, prompting


    for the passphrase if needed. Also sets the Fabric env.keyfile_name


    property.


    """


    keyfile_path = os.path.join(KEY_DIR, keyfile_name)



    # Start pageant. Note that this works with the PuTTY key format (*.ppk), not

    # the OpenSSH format.


    path_to_pageant = os.path.join(PUTTY_DIR, 'pageant.exe')


    result = subprocess.call([path_to_pageant, keyfile_path])


    if result > 0:


        raise OSError, "Bad result %s" % result



    # Store the path to the key file in fabric's global env dictionary

    env.key_filename = keyfile_path



def base():

    """


    Set up for connection to the base server for provisioning of


    """


    # Once DNS is set up for these hosts, I can use hostname instead of ip address


    env.user = 'me'


    env.hosts = ['me@10.0.0.7']


    _start_pageant_and_store_key('UAT_PrivateKey2.ppk')



def uat_up():

    run('cd uatbox32 && vagrant up')



def uat_destroy():

    run('cd uatbox32 && vagrant destroy -f')

No comments: