# Link List for Lab-ONE (Vagrant)

**URL:** <https://forum.opennebula.io/t/link-list-for-lab-one-vagrant/3180>\
**Category:** Integration Support\
**Created:** [October 26, 2016, 10:01am UTC](https://forum.opennebula.io/t/link-list-for-lab-one-vagrant/3180 "2016-10-26T10:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darkfader](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/darkfader/32/4769_2.png) [@darkfader](https://forum.opennebula.io/u/darkfader)\
**Post date:** [October 26, 2016, 10:01am UTC](https://forum.opennebula.io/t/link-list-for-lab-one-vagrant/3180/1 "2016-10-26T10:01:05Z")

</div>

## Vagrant

###Intro for starters:  
[http://www.cyberciti.biz/cloud-computing/use-vagrant-to-create-small-virtual-lab-on-linux-osx/](http://www.cyberciti.biz/cloud-computing/use-vagrant-to-create-small-virtual-lab-on-linux-osx/)

### Plugins or “providers” & OpenNebula

> **[Custom Providers - Plugin Development | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/plugins/providers)**
>
> This page documents how to add support for new providers to Vagrant, allowing
> Vagrant to run and manage machines powered by a system other than VirtualBox.
> Prior to reading this, you should be familiar with the plugin development
> basics.

> **[GitHub - eucher/opennebula-provider](https://github.com/eucher/opennebula-provider)**
>
> Contribute to eucher/opennebula-provider development by creating an account on GitHub.

### Template Requirements (Default key, User, PW)

What needs to be adjusted in a ONE template to be a proper Vagrant Box.

> **[Creating a Base Box | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/boxes/base)**
>
> There are a special category of boxes known as "base boxes." These boxes
> contain the bare minimum required for Vagrant to function, are generally
> not made by repackaging an existing Vagrant environment (hence the "base"
> in the "base box").

What’s rarely mentioned, you are also supposed to set root pw to “linux”. Should you chose to do that, make sure that VNC is protected!

### SSH settings

> **[config.ssh - Vagrantfile | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/vagrantfile/ssh_settings)**
>
> The settings within "config.ssh" relate to configuring how Vagrant
> will access your machine over SSH. As with most Vagrant settings, the
> defaults are typically fine, but you can fine tune whatever you would like.

Not all settings work reliably, i.e. agent forwarding. Keep that in mind if you try out some.

### patch skytap (retry)

There’s a big issue when SSH gets back a net unreachable (seems this is in NAT scenarios). Vagrant doesn’t have any _working_ error handling for this. Use the following plugin and overload the builtin one in action.rb (see my slides for that!)

- [Retry SSH connection if network is unreachable · Issue #74 · mitchellh/vagrant-aws · GitHub](https://github.com/mitchellh/vagrant-aws/issues/74)
- [http://www.rubydoc.info/gems/vagrant-skytap/0.1.8/VagrantPlugins/Skytap/Action/WaitForCommunicator](http://www.rubydoc.info/gems/vagrant-skytap/0.1.8/VagrantPlugins/Skytap/Action/WaitForCommunicator)

## Networking

### How to NAT?

> **[\[one-users\] KVM default NAT networking and port forwarding](http://lists.opennebula.org/pipermail/users-opennebula.org/2013-November/042655.html)**

Easy NATting with a dedicated bridge. This means the VM’s stay a bit more “private” like a normal VirtualBox VM. Don’t go crazy with adding port forwards though, instead use a VPN, see next step.

### With a VPN

> **[OpenVPN - Debian Wiki](https://wiki.debian.org/OpenVPN)**

> **[How To Set Up an OpenVPN Server on Debian 8 | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-debian-8)**
>
> A Virtual Private Network (VPN) allows you secure access to a remote server. In short, this allows the end user to mask connections and more securely navigat…

Don’t forget to push your route or set it up in the VPN Client.

### Importing Template (vboxmanage!)

A base “feature” of Vagrant which devs loved it for is being able to download insecure, untested and dangerous images off the internet. This is not easily possible - we just give them a template name/ID but we don’t allow downloading images.  
But ACTUALLY it would be possible. The boxes are just Virtualbox images so one could download them on the Frontend, mount them & install ONE-context.

An example can be found here:  
[https://github.com/kraksoft/vagrant-box-debian/releases/download/8.1.0/debian-8.1.0-amd64.box](https://github.com/kraksoft/vagrant-box-debian/releases/download/8.1.0/debian-8.1.0-amd64.box) ?

If you want to support your devs’ workflow you might as well go the full way and make a tool for them to download the box on the server & try to autoconvert it.  
(don’t make them SCP around, it’s supposed to be FASTER after all)

Personally, I don’t want to use any of those premade images.

## SSHFS

- sshfs forward and remote (sftp)  
[Vagrant: Sharing folders with vagrant-sshfs - Fedora Magazine](https://fedoramagazine.org/vagrant-sharing-folders-vagrant-sshfs/)
- sshfs remote host + key  
[GitHub - dustymabe/vagrant-sshfs: SSHFS synced folder implementation for Vagrant.](https://github.com/dustymabe/vagrant-sshfs#options-specific-to-arbitrary-host-mounting)
- sshfs + user home chroot  
This is a suggestion: If you SSHFS-mount a special fileserver, you can chroot the users on it so the Vagrant access gets really limited to what everyone wants to see in their own VMs.

## Open Topics

Naming conventions (how to differentiate vagrant and normal images)!

I think the safest way is to make the images as hybrids, but you would need to make sure the “vagrant insecure SSH key” is only active IF the VM was created using a Vagrant user!  
**Otherwise it would not be replaced by a safe one!**

### Conflicts with one-context

- don’t set your hostname twice
- check your VM’s /etc/hosts is fine

## other plugins

- Vagrant --provider flag?  
[[one-users] [VirtualMachineAllocate] Error allocating a new virtual machine. Only one CONTEXT attribute can be defined.](http://lists.opennebula.org/pipermail/users-opennebula.org/2014-July/045612.html)

## issues

> <https://stackoverflow.com/questions/29572211/vagrant-ssh-doesnt-work-as-expected-it-doesnt-honor-my-custom-settings>

[http://lists.ceph.com/pipermail/users-opennebula.org/2013-December/043159.html](http://lists.ceph.com/pipermail/users-opennebula.org/2013-December/043159.html)  
(can’t use spaces!)

## Other approaches

- onedock:  
[http://opennebula.org/opennebula-docker-driver-and-datastore/](http://opennebula.org/opennebula-docker-driver-and-datastore/)  
docker-machine:
- onegate
- rOCCI  
[https://gilda.ct.infn.it/documents/26990/a262e901-658a-4276-b16d-9eae5e037795](https://gilda.ct.infn.it/documents/26990/a262e901-658a-4276-b16d-9eae5e037795)  
[GitHub - gwdg/rOCCI-server: An OCCI service provider](https://github.com/gwdg/rOCCI-server/)

---

<div class="post-metadata">

**Author:** ![darkfader](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/darkfader/32/4769_2.png) [@darkfader](https://forum.opennebula.io/u/darkfader)\
**Post date:** [October 26, 2016, 12:57pm UTC](https://forum.opennebula.io/t/link-list-for-lab-one-vagrant/3180/2 "2016-10-26T12:57:04Z")

</div>

Normally Vagrant requires a pre-setup of the Vagrant user and SSH key (as described in the links above).  
Today I learned about adding boot scripts in ONE and wondered if they can be used for this.

Turns out: Yes. Here’s a bootscript which should mostly work for CentOS/Debian/Ubuntu and sets up the important parts.  
Just, please MAKE SURE you click “Encode Script in Base64”.

```
useradd vagrant
mkdir -p /home/vagrant/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys
chown -Rh vagrant: /home/vagrant
chmod -R 700 /home/vagrant
chmod 600 /home/vagrant/.ssh/authorized_keys
sed -i 's/#UseDNS.*yes/UseDNS no/' 's/.*GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config\
&& systemctl restart sshd

echo "%vagrant ALL=NOPASSWD:ALL" > /etc/sudoers.d/vagrant

```

If you find you need something more robust for this script, let me know.  
One thing I know is that the UseDNS/GSSApi regex might not work on all distros, or the service name might differ. But for that case you can just slightly modify your scripts.  
For now, I would say it is good enough, but there’s no warranties ever 🙂
