Vagrant

From Wildsong
Jump to navigationJump to search

"Vagrant" is a system for managing virtual machines.

http://vagrantup.com/

You set up a config file that sets up the vm, including installing packages and configuration settings.

Normally I run Parallels to use virtual machines on my Mac, but as of version 11, I have to pony up another $20 to get the pro version for Vagrant, and there is no current Debian provider. So I am going back to using VirtualBox for now.

Running a squid proxy

I put a proxy on Bellman so that I don't have to pull every DEB package over the Internet every time I create a new Vagrant machine.

apt-get install squid-deb-proxy squid-deb-proxy-client

On each client you can install the avahi client software and it will automatically find the server.

apt-get install squid-deb-proxy-client

The debian proxy runs on port 8000, the standard squid proxy runs on 3128 If you want to use squid as well as the dpkg cache then you need to edit /etc/squid3/squid.conf to add an acl -- acl localnet 192.168.1.0/24 for example

Using a generic Debian box

mkdir generic cd generic vagrant init debian/jessie64; vagrant up --provider virtualbox vagrant up

Keeping guest additions up to date

Install this plugin: https://github.com/dotless-de/vagrant-vbguest

Building a custom box

All the details

https://blog.engineyard.com/2014/building-a-vagrant-box

Refinement: Make the virtual hard drive smaller, there is no earthly reason for it to be 40GB. The default 8GB is big enough, in fact 4GB would be fine.

Quick version

Build a virtualbox. Use a 4GB VMDK drive. Turn off audio and USB, put the network interface in bridged mode so it gets a real IP.

Install Debian into it. Name the machine 'vastra', create 2 accounts, root and vagrant. Use this as a proxy: http://192.168.1.2:8000/ Install only the ssh server and the system utilities here.

Boot the machine and set it up.

  • I am only running the machine from vagrant (ssh) I don't need the guest additions. Bypass those instructions.
  • Ignore the instructions about setting root password, this is Debian and you did that already.

You do need to set up sudo. This works- log in as root--

apt-get install sudo
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vagrant

I want it to use a proxy for all downloads, the first "vagrant up" is no faster but from then on it gets packages from my local cache.

apt-get install squid-deb-proxy-client
  • Since we just installed from the 'net there is no reason to update/upgrade now. You can if you want.

Set up keys. Log out from the virtualbox console and log in via ssh as user vagrant so you can paste this:

mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh

You already installed the SSH server but still need to edit config. I do it like this

sudo -s
echo "AuthorizedKeysFile %h/.ssh/authorized_keys" >> /etc/ssh/sshd_config

Zero out the box and shut it down

dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
poweroff

Package it!

cd ~/Projects/vastra-box
vagrant package --base vastra-4gb
mv package.box vastra-4gb.box

Add it to your inventory

vagrant box add vastra-4gb vastra-4gb.box

Test it!

vagrant init vastra-4gb
cp ../vastra-ansible/Vagrantfile .
# Adjust settings as needed, will this be a pbx or dev machine?
emacs Vagrantfile
# Deployment machines don't need this
# but development machines do-- allows shared folders to work
vagrant plugin install vagrant-vbguest
vagrant up

This should bring the machine up and provision it to be a Vastra box all in one go.

Make a note to look at Packer to further automate this...

Vastra development machine

I need to be able to run a test machine on the Mac so that I can go offline in Gold Beach. And maybe so that I don't mess up our phones every time I get crazy testing.

cd ~/Projects
mkdir vastra-debian
cd vastra-debian
vagrant init vastra-4gb
cp ../vastra-ansible/Vagrantfile .
# Select dev options
emacs Vagrantfile
# Allow shared src folder
vagrant plugin install vagrant-vbguest
vagrant up
vagrant ssh

You can log into the Squid cache machine and tail its log to see that it is indeed caching package requests from the vm.

ssh bellman
sudo tail -f /var/log/squid-deb-proxy/access.log

I also need to be able to simulate a target machine, one stripped down to the minimal requirements to run Vastra.

cd ~/Projects
mkdir pbx
cd pbx
vagrant init vastra-4gb
cp ../vastra-ansible/Vagrantfile .
vagrant up
vagrant ssh