Running virtualbox/vagrant in a cloud instance - vagrant

I've tried two things:
First, I tried to install virtualbox on a EC2 machine, which proved to be impossible.
Second, I was able to install both vagrant and virtualbox on a Digital Ocean droplet, but when I tried to run vagrant up, it got stuck on Booting VM.
Several sources on Internet say that it is not possible to run a VM inside a virtualized environment (both Amazon and Digital Ocean provide this).
Is there any way I can solve this with another provider, or is there a way to run vagrant/virtualbox in Amazon or Digital Ocean?

Install VirtualBox and Vagrant on a physical machine such as your desktop
Run the 3 commands from the command line:
vagrant init somenameyoumakeup file://urlToYour.box
vagrant up
vagrant halt
Open the VirtualBox UI
Export the Virtual machine to OVA format using the File -> Export menu
Follow the guide here for importing an OVA: https://aws.amazon.com/ec2/vm-import/

Related

Can cloud-config be used to provision a Vagrant box?

I'd like set up a development Vagrant VM using the same could-config file I'd use to provision a production VM. Vagrant doesn't have a built-in cloud-init/cloud-config provisioner, though. Is there still some way to do that?
Cloud-Init is not nativelly supported on Vagrant box images, instead the included vagrant provision do the job.
However there is a way to do it with VirtualBox
Install from scratch a VM using the distro ISO
Install cloud-init on the VM.
Stop and convert the VM to template.
Then the deployment of a new VM
Save the user-data and meta-data as an iso file
Clone the template and start it with the iso attached

Use Windows with Virtual Box as Host and VM guest for managing with Vagrant and Ansible

Is there a way for next scenario as I am planing to setup lab environment:
physical desktop running Windows 8 platform
on Windows 8, I plan to install ONLY Virtual Box 5.1
then on VirtualBox to setup CentOS system
and then on CentOS will be running Vagrant and Ansible (no VirtualBox installation)
Question: Is there any way that this setup will work to create new environments via CentOS as Vagrant-Ansible manage servers?
------------------------edit----------------------
Thank you for your answer. I try to setup as I mentioned above without luck. I am new user of Vagrant and Ansible so I am having trouble to make it work. I setup Linux system on VB, install vagrant, install Ansible but when I hit 'vagrant up' I am getting error that "No usable default provider could be found for your". I am following documentation form official sites but can;t make it work. Then I try to install VirtualBox inside Linux system and now it is working but defined machines with Vagrant installs inside Linux machine (where are Vagrant and Ansible installed) and not on Host VirtualBox. Any advice? I hope it is clearer now. Thanks
I have had some success in using a Windows Ansible Host and running using Vagrant with this host.
I have scripted how to setup Win Ansible and the shims at:
https://github.com/taliesins/win-ansible
The important bit is to setup shims that call bash scripts running under cygwin.
Another important thing to consider is, is that it is probably better to generate your own inventory file (put it in the vagrant file before you create VMs) then to use an auto-generated inventory file.
If you environment is not simple consider not using Vagrant provisioner for Ansible, but rather call Ansible via command line at the end of the vagrant file (after you have created the VMs).

Running vagrant on two macs

I have Vagrant installed on my iMac but I would also like to install and run it on my MacBook. Is it possible to run the same Vagrant box across two Macs?
I have done a Vagrant up command within a shared Dropbox folder - so i'm guessing that all I need to do is install vagrant on the second mac and then navigate to the Dropbox shared folder and do vagrant up.
Would this work?
Known solution:
ssh to the host machine
user#MacBook: ssh user#imac
then vagrant up; vagrant ssh.
user#imac: vagrant up; vagrant ssh
vagrant#vagrantvm:
This would be the most straight forward way I can think of.
Another option:
RDP to imac and run vagrant up;vagrant ssh as normal
Yet another option:
If your vagrant file is complete enough you should be able to vagrant up on any host to give you the same vagrant env. This relies on your use case but is how I use vagrant.
Vagrant stores the state of the machine and machine id inside the .vagrant folder. The running machine (vm) itself is handled by virtualbox/vmware or any provider your using. Lets say the virtualbox box is stored somewhere else on your system and referenced by Vagrant.
If you access the folder from two systems your basically remote controlling two different machine on two different systems. Not a good solution. Furthermore, you will run into problems if the states are different, e.g. its "up" on system one but "destroyed" on system two.
Additionally to the above solutions I propose the following:
Vagrant Share! Enable Vagrant http-/ssh-Share between your systems.
Vagrant machines should be repeatable and destroyable. Therefore, put your Vagrantfile under version control and checkout on the two systems.
Configure your provider to store the box itself on the dropbox.

How do share the same VM between Windows and Linux when using Vagrant?

I have two hosts, one Windows and one Linux, both with Vagrant and VMware Workstation installed and everything works perfectly fine in their own environment. However, when I create an guest VM in Linux and I do vagrant up in Windows, then Vagrant will delete(!) everything in the .vagrant directory and attempt to fetch the base image. The same thing happens if I do a vagrant init and vagrant up in Windows and then a vagrant up in Linux. How do I prevent this from happening? Is there anyway to share the same VMs between Windows and Linux using Vagrant?
I'm running Windows 7, Ubuntu 14.04, Vagrant 1.6.5, VMware Workstation 10.0.3. This problem occurs for all guest operating systems.
The content of the .vagrant directory can be OS specific, and the internal state of VMware for sure.
I don't think there is easy way to share the same VM instance between the two hosts. The Vagrant way is to provision the VM so you only share the base box and then each user/OS spins up their own instance.
Another option would be to use vagrant package and vagrant box add to transfer the configured box, but that doesn't work with the VMware provider.
Yet another approach would be to use a cloud provider like AWS or Digital Ocean and just ssh into the box. Or maybe even use the vagrant-managed-servers plugin. Your question didn't hint what you use the Vagrant VM for, so it's difficult to tell what would be the best solution.
The following has been tested using the VirtualBox Vagrant provider with Windows 10 and Ubuntu 18.04 in a dual boot setup with a shared NTFS drive where D:\ in Windows is accesible as /mnt/d/ in Linux.
First (but not indispensable if I'm not wrong), set the VAGRANT_HOME environment variable in both Windows and Linux to the same place, e.g.:
Windows, D:\.vagrant.d
Linux, /mnt/d/.vagrant.d
Then create a new machine from one of the OSes, from Linux in the following example:
$ cd /mnt/d/vagrant_machines/machine1
$ vagrant init
$ vagrant up
Then boot in Windows and first backup D:\vagrant_machines\machine1\.vagrant just in case case its contents get accidentally deleted.
Then register from VirtualBox the existing VM, e.g. D:\virtualbox_machines\machine1_default_1587262647987_91775\machine1_default_1587262647987_91775.vbox.
Then run the following:
>vagrant.exe status
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.
The UID used to create the VM was: 1000
Your UID is: 0
And update D:\vagrant_machines\machine1\.vagrant\machines\default\virtualbox\creator_uid to your current UID (0 in this example).
Then start the machine:
>vagrant status
>vagrant up
Finally, note that you will require to update the creator_uid each time that you switch OSes, which you might want to automate.

Windows 8 HOST Vagrant spinup GUEST Ubuntu dev followed with Ansible manage dev stack from GUEST

I am working with Vagrant to provision Ubuntu servers using bash. I would like to cut my teeth on Ansible however I understand that Ansible does not currently run on Windows Host.
Is something like the following a reasonable work-around?
On Windows Host, use Vagrant to spin-up a basic Ubuntu Dev Box, including Ansible tools. From the Guest Dev Box use Ansible to run local tasks to further build it out. From the Dev Box I would use Ansible to spin-up/manage other Digital Ocean droplets from this Dev Box.
Your easiest workaround is probably to use virtualbox to start a linux/ubuntu virtual running on your Windows box, then to run Vagrant inside of that virtual. Yes, it's turtles all the way down- windows running virtualbox+ubuntu running virtualbox+ubuntu+vagrant.
Of course, the first layer won't be managed by Vagrant or Ansible, though you could do most of the configuration management after bootstrapping it.
Another option is to have a small dev box in your virtual hosting provider (Digital Ocean) where you manually install and launch vagrant/ansible from.
Alternately, dual boot or switch to a Linux or OSX machine :)

Resources