Rebuilding a Virtual Machine After Deleting It

This is a note to remind myself how to set up a new VM for development. This is a mess, not a tutorial.

This works on a target environment with this uname -a:

Linux marinela 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

My host system is set up to run a bunch of VirtualBox VMs. I have a VM network setup, and want to be able to throw away the VMs and start fresh, reconstructing them with an Ansible playbook. This is about re-installing the dev machine (which is the most complex machine).

The .ssh/config lines for this host are:

Host dev.hif.lo
  Hostname dev.hif.lo
  IdentityFile ~/.ssh/id_rsa
  User vagrant

(As usual, I'm inching toward using Vagrant, so I set it up like Vagrant says to. DNS defines the hif.lo network, all with static addresses. Keys are already made.)

Go into the VM console and edit /etc/network/interfaces to set the IP address. Edit /etc/hostname to change the name.

# this is done via the console
sudo -s
vi /etc/network/interfaces
vi /etc/hostname

Copy relevant keys: to get in, and id_dsa for github. Then ssh in.

# host$ 
scp -o PreferredAuthentications=password -o PubkeyAuthentication=no ~/.ssh/ dev.hif.lo:
scp -o PreferredAuthentications=password -o PubkeyAuthentication=no ~/.ssh/id_dsa dev.hif.lo:
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no dev.hif.lo

The on the dev VM, we move the keys into the proper locations.

# dev$ 
mkdir .ssh
mv .ssh/authorized_keys
mv id_dsa .ssh

And test ssh into there: ssh dev.hif.lo

Shut down the system, and make a snapshot.

Setup the rest with Ansible

I won't go into detail here, but the idea is to rebuild from scripts.

There should be an error message about an rsa key. Copy it over and install it.

ansible-playbook common.yml --limit dev.hif.lo
ansible-playbook dev.yml --limit dev.hif.lo