Vagrant
Vagrant is an easy way to setup and configure system images for virtualbox, but also AWS (amazon). So for cloud deployment this is a very interesting package.
Disable check for updates in Virtualbox. Vagrant does not keep the same pace and won't work directly with new release.
Last time it was a stable release (6.1) and you will have to wait until vagrant 2.2.7 to have this fixed !!! There was a fix : visit
But virtualbox works fine and you should only update it manually when you have the time to fix problems.
quick start
Type :
| osx | |
|---|---|
For the init step, you need to specify an image to base the VM on, if you want another OS you could choose here : visit If it is not there some manual configuration should be needed... later !
Virtualbox and vagrant
Simplest version and free of course. Normally you start in a separate directory :
| init a new vm | |
|---|---|
This downloads an image from visit. So it is clear the image is taken from visit and it has to exist. This particular example is an ubuntu (precise pangolin) 32 bits image. See the page in question for your options :
It simply says : "We make Vagrant, Vagrant Cloud, and other products." So be it....
or search it : visit
The vagrant up then does everything, download the image, startup a new vbox image. vagrant ssh log's you in, if you need root access, do 'sudo su' vagrant destroy removes the whole thing without a trace (almost: Vagrantfile remains).
If you look at the Vagrantfile created in this directory by vagrant init , there is a lot of comments, and actually only one plain line :
| Vagrantfile | |
|---|---|
Of course this is the reference to the image, another example could be :
config.vm.box = "opscode-centos6.6" config.vm.box_url = "[http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode\_centos-6.6\_chef-provisionerless.box](http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.6_chef-provisionerless.box)"
In this case, the url also has to be given, see the amazon section about this version. Another entry we like is the network interface
| Vagrantfile | |
|---|---|
Vagrantfile is in ruby style, so you might see constructs like
See ruby docs about that. In short, do..end is a code block, or closure. And they must follow a method invocation. So that's the configure() in this case. Inside this method the code block called using the yield keyword with a parameter specifying the config parameter between ||.
If you want the provisioning be done with ansible you could end up with this minimal Vagrantfile :
| Vagrantfile | |
|---|---|
Vagrant up will provision it the first time, after that you need to :
| provision afterwards | |
|---|---|
If you encounter problems like :
| machine facts | |
|---|---|
Make sure you remove user: root from the playbook, not :
but
note:: you can also skip ansible and provision with a simple bash script
A simple example of that (working freeipa example)
This can be run with parameters from vagrant like this :
vbguest plugin
This could have been a nice plugin, but it sadly causes more problem than advantages.
sadly (2017) this is still not worth the effort of installing in a proxy environment.
I will explain the problems though.
installation
In an ideal world :
That would be it! But in the proxy setup at RINIS we get this problem :
| error | |
|---|---|
The problem is that this happens at an early stage where we did not make the box proxy-capable yet. You should :
- vagrant up on a vagrant box with the proxy settings as shown above
- this will fail, but you can log in to the box. So do a yum update
- now do a vagrant halt
- vagrant up, it seems to come a long way installing but still says failure
- log in again and do /etc/init.d/vboxadd restart by hand.
- now it works
And that each and every time you startup a new vagrant box. So i ended up doing :
vagrant plugin uninstall vagrant-vbguest
downgrading a box
A special problem with the geerlingguy/Centos7 box was that the vbguest plugin failed to work after an upgrade to at least 1.2.12
So i wanted to step back boxes until it works again. There is no downgrade command in vagrant, but you can just do :
| downgrade | |
|---|---|
Just don't update anymore until it mentions the vbguest problem is fixed.
Here are the steps back until it worked again.
version 1.2.11 (one step back)
This complains about mismatching guest versions:
| status | |
|---|---|
Note that this is what you get in one directory (demo) but in ldap it just says :
| output | |
|---|---|
Also the box must be running, so it seems like something on the running machine and not the directory config.
Now the host version is quickly found, login to the VM and type :
That's one down, but where does the 5.2.20 come from ?!?
List the vms under your own name !
Copy the key between {} and use it to query the vm :
| query specific vm | |
|---|---|
If you try the other ones they will give all kind of different(older) versions, so each VM definitely has it's own vbox additions installed.
If you downgrade even further things become more clear. On the website with the geerlingguy boxes he stopped mentioning the guest addition versions after V1.2.7 visit
So i stepped back to 1.2.7 and indeed, after installation :
So this leads me to two statements:
GuestAdditions versions on your host (5.2.18) and guest (5.2.20) do not match, means host is the hypervisors version of VBox+GuestAdd and guest is the Additions version that the box was installed with.
If the host is newer than the box, it seems fine, the other way around means trouble. Just try to match them up! (geerlingguy 1.2.10 works)
creating your own boxes
This is described here : visit but.. it directly states that this is a tedious process, and i surely opt for the alternative, which is to get a default box and extend it to my own needs.
This is very simple : source visit
First vagrant up the box you need to extend, and go ahead installing software etc. After you are satisfied, perform these steps :
make the box as small as possible
sudo apt-get clean
However: It does seem to be good practice but the first thing you will have to do is a apt-get update the get the cache back.
I therefore chose not to clean the cache and leave my box as-is
repackage the box
You could now bring down the box (halt !!, not destroy!!), but the next command will do that anyway :
vagrant package --output mynew.box
The file can be anywhere on the system, this command puts it into the current working directory, in the next step the place is remembered so you might want to move it to a common location. The other boxes where in :
mv mynew.box ~/.vagrant.d/boxes
Add the box to your vagrant install
vagrant box add mijnbox ~/.vagrant/boxes/mynew.box
Alter the box in your vagrant file :
And vagrant up your new box.
amazon
Troubleshooting vagrant
symptom
| error | |
|---|---|
Just after starting vagrant up. The -vvvv will not do anything.
diagnose
Unknown, i only added an apparent cure.
cure
Add a line to map the port (useful if you want to steer ports anyway) :
config.vm.network "private_network", ip: "192.168.33.10"
becomes :
config.vm.network "private_network", ip: "192.168.33.10" config.vm.network "forwarded_port", guest: 22, host: 2223, id: "ssh", auto_correct: true
box-cutter/centos70
This particular box has a problem with the vagrant vboxguest plugin, it will fail with :
| error | |
|---|---|
And inspecting the log file will reveal something about :
| log | |
|---|---|
Now this is a known problem, and a workaround is to login to the box and do as root :
cd /usr/src/kernels/2.6.32-431.el6.i686/include/drm/
ln -s /usr/include/drm/drm.h drm.h
ln -s /usr/include/drm/drm_sarea.h drm_sarea.h
ln -s /usr/include/drm/drm_mode.h drm_mode.h
ln -s /usr/include/drm/drm_fourcc.h drm_fourcc.h}
And then run the vagrant vbguest again, this time it will succeed.
no SATA controller
I was generally using SATA Controller as the controller to add new disks, because these were part of the box-cutter images by default. However, begin December 2016 an update of either Virtualbox, the guest additions or the box-cutter images cause the networking to fail. So i had to find another base for the centos7 boxes. The most prominent one is on the Vagrant site itself : visit , it's the centos/7 box mentioned there. However it does not have a SATA controller, so this line won't work :
| create harddisk and SATA controller and attach | |
|---|---|
Note: startup the VM and look at the 'storage' section to see if the SATA controller is defined, and also what the exact name is !! It could be named just "SATA" or "SATAController" or "Dave". The name MUST match.
Otherwise you might just want to use IDE controllers because these are default. :
| IDE controller | |
|---|---|
A working way to install mate desktop on box-cutter/centos7
All centos boxes seem to want to install vbox guest additions, but not the X11 additions. So somewhere the -nox11 option is explicitly added. But also it is in the way when installing them yourself with vagrant-vbguest. Here is a way to reinstall everything that worked :
| list vms | |
|---|---|
Remember/or cut'n'paste the name of the box, let's say 'my-box' Then reset the name and check that it is empty
| get version | |
|---|---|
So the last command should say: "No value set!" Now login in to the box and uninstall the current guest additions :
| uninstall guest additions | |
|---|---|
Fill in the correct versions. Now run the installer again , with verbose output:
| install again | |
|---|---|
This should either install ok, or give you a lot of info about what might happen. Note : it almost always says it failed with a messages like :
So you better just check if it works first, before debugging.
Now you have a virtualbox with two more problems: There were no icons in most of the menu's of the MATE installation, and at every login there was a popup about VBoxClient. I added both as separate chapters for easier lookup :
VBoxClient: the VirtualBox kernel service is not running. Exiting
I have no idea what caused this but on a hunch i tried to boot the second kernel line instead of the first , it was 3.10.0-327 vs 3.10.0-327.4.4. Since that worked i chose the pragmatic way and altered the boot menu of grub. To do that first view /etc/grub2.conf, which contains the strings of the menu options. This file is regenerated so moving the second menu up does not work (i tried ;) . Copy the string from the menu you want to boot and place it in the file /etc/default/grub instead of the line :
| /etc/default/grub | |
|---|---|
Alter it to contain the saved string :
| contains | |
|---|---|
Then rerun the grub configuration :
| configure grub again | |
|---|---|
And reboot to see the second option is booted now. Then login to check if the VBoxClient messages is gone.
No icons showing in the MATE desktop menu's
The last time i fixed it with :
| mate | |
|---|---|
This has been added to the mate-desktop role now, making all packages installed for mate :
And i specifically deleted mate-screensaver because it occasionally hangs the desktop.
| remove the screensaver | |
|---|---|
After this, i made a new box with :
And install locally :
| install local | |
|---|---|
Or remotely :
| remote | |
|---|---|
Then use this url to fetch it.
| fetch image | |
|---|---|
Though this will not be enough when behind a proxy , see next chapter. proxy problem
When getting a box from repo.rinis.nl it means we want to bypass the proxy and go straight for repo.rinis.nl. However vagrant is in fact ruby and ruby takes the environment and uses that in it's scripts. So it will adopt http_proxy=http://10.10.1.13:3128 and timeout on the download of the box.
Unsetting the environment each time you start a vagrant download is not even an option, so use the following lines in the Vagrantfile itself :
It instructs ruby to unset an environment variable for this script only.
Vagrant hd problem : VERR_ALREADY_EXISTS
Vagrant fails to create a harddisk file for Virtualbox with lines like this :
file_to_disk="./sdb.vdi" vb.customize ["createhd", "--filename", file_to_disk, "--size", 500 * 1024 ]
And it will say :
Actually it will work when you rename the disk file to './sdg.vdi' or something. You can look up what's wrong in the virtualbox interface under 'file'->'virtual media manager' and there will be some erroneous disk names, so just remove them or fix in some other way.
You will see in that list that multiple disks with the same name are normal, just all red ones should be fixed.
Workaround We seem to be stuck with this problem for a while until they fix it. We already went back from vagrant 1.8.5 to 1.8.4 for the 'key insertion' problem. But how far back do we go for this error. 1.8.4 does not fix it So maybe until that time use this workaround that detects the existence of the disk in the Vagrantfile. Actual example of the repo server script (with two attached disks) :
Vagrant+ansible --limit does not match any hosts
Complete error :
| error | |
|---|---|
This error occurs when you do not define a default host in the hosts file. For instance this hosts file will not work:
| inventory | |
|---|---|
But adding this group will work :
Installing vbguest problem
When trying to install vagrant vbguest on a machine that already has a vboxadd installation:
You can get rid of this by removing the complete tree at /opt/VBoxGuestAdditions on the target machine. Then run the command again :
| rerun | |
|---|---|
Windows testing images
To test Internet Explorer versions in particular, you might not want to buy windows. There is an easy way with vagrant. Microsoft offers VM installations for various combinations of windows and explorers for you to test. See :
There are versions for Virtualbox, VMWare but also vagrant. To install, download and unzip the image, which will give you a .box file. The file will be the basis for the vagrant box so place it somewhere safe (not Download) and add it like this :
| windows vagrant images | |
|---|---|
There are more flavours, like IE8,IE9,IE10 and IE11 for windows7 and IE11 for windows 10. I just tried the w7 ones. Now to avoid the same search for proxy settings as always, it is hidden here :
start->control panel->network and internet->internet options->connection->lan settings->proxy..
Now these are virtual machines that expire after 90 days, i presume that is from the installation point and not the download point !? Any way microsoft itself advises you to take a snapshot right after installation and restore that at/after expiration. Todo: test if vagrant destroy/vagrant up also works !
symptom
The machine does not start up but just says 'aborted' Servert, demo install.
diagnose
First re-enable the gui. maybe that gives more info. In general, you can enable debugging with --debug and reread any Vagrantfile changes with reload.
| debug vagrant | |
|---|---|
This clearly hints at network manager (again), but also weirdly it starts up when run like this !?!
cure
Not sure yet, for now it worked to remove network manager, but that also seemed to tear-down X so these steps might get you back on track :
| network manager | |
|---|---|
automatic key for ansible
Many use cases are in combination with vagrant to get a working system, but it does mean installing the key manually :
| manual install | |
|---|---|
An extra action needed. But there are also boxes that come with ssh login disabled. This time it means :
| first enable sshd then install | |
|---|---|
That would mean 6 extra actions. So there is a way to shorten this and use your own key on each of these machines.
Be careful how you use these boxes. Only do this for local testing !!
The private key will be installed on the box (!!) if you do it like this:
I included a complete example for quick usage, but the 3 lines do this:
- config.ssh.insert_key : stop the normal insertion of a random generated key
- private_key_path: set the path of all keys (can be multiple)
- provision : install the public key into authorized keys.
You can now start ansible without any extra commands.
there was an error when attempting to rsync a synced folder.
This stopped vagrant up on my owb_forms vm. here are some of the errors displayed
| error | |
|---|---|
It seems to happen when transferring the generated private key. To be short : adding this to Vagrantfile helps :
| Vagrantfile | |
|---|---|