Vagrant: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Created page with ""Vagrant" is a system for managing virtual machines You set up a config file that sets up the vm, including installing packages and configuration settings."
 
Brian Wilson (talk | contribs)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
"Vagrant" is a system for managing virtual machines
"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.
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/stretch64
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.
Quick version
'''Build a virtualbox.''' Use 8GB 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.'''
* When I need guest additions (on a development machine) I install them later. That way they are always up to date.
In [[Debian preseed]] I set up the user accounts and packages so that's done on first boot of the virtual machine. I includef openssh and sudo in the preseed file, and I set up a proxy so repeated slow Internet downloads are eliminated.
That leaves only a few things to do on first boot.
'''Set up keys.''' Log out ssh as user vagrant so you can paste this:
mkdir .ssh
chmod 0700 .ssh
cd .ssh
wget http://bellman/vagrant.pub -O authorized_keys
chmod 0600 authorized_keys
chown -R vagrant ~/.ssh
su
# Allow "vagrant" to use "sudo"
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vagrant
# Edit ssh config to allow keys.
echo "AuthorizedKeysFile %h/.ssh/authorized_keys" >> /etc/ssh/sshd_config
# Zero out the box
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
poweroff
'''Package it.''' This turns the VM into a Vagrant Box.
cd ~/Projects/vastra-box
vagrant package --base vastra-8gb
mv package.box vastra-8gb.box
'''Add it to your inventory'''
vagrant box add vastra-8gb vastra-8gb.box
'''Test it!'''
vagrant init vastra-8gb
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

Latest revision as of 05:34, 1 December 2018

"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/stretch64
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.

Quick version

Build a virtualbox. Use 8GB 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.

  • When I need guest additions (on a development machine) I install them later. That way they are always up to date.

In Debian preseed I set up the user accounts and packages so that's done on first boot of the virtual machine. I includef openssh and sudo in the preseed file, and I set up a proxy so repeated slow Internet downloads are eliminated.

That leaves only a few things to do on first boot.

Set up keys. Log out ssh as user vagrant so you can paste this:

mkdir .ssh
chmod 0700 .ssh
cd .ssh
wget http://bellman/vagrant.pub -O authorized_keys
chmod 0600 authorized_keys
chown -R vagrant ~/.ssh
su 
# Allow "vagrant" to use "sudo"
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vagrant
# Edit ssh config to allow keys.
echo "AuthorizedKeysFile %h/.ssh/authorized_keys" >> /etc/ssh/sshd_config
# Zero out the box
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
poweroff

Package it. This turns the VM into a Vagrant Box.

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

Add it to your inventory

vagrant box add vastra-8gb vastra-8gb.box

Test it!

vagrant init vastra-8gb
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