how to get files from host machine to vagrant VM (MAC OS) - vagrant

I haven't used vagrant for a while so I am racking my brains out on this one.
I know for a fact that one way to "exchange files" between the host machine and the vagrant VM is to copy any file you need into the host machine's vagrant folder that holds the Vagrantfile - the SAME folder where you run 'vagrant up' and 'vagrant ssh' to get connected to the /home/vagrant folder (indicating that you have entered the vagrant vm). However, when I get into the vagrant vm folder /home/vagrant I do not the files that I added in the host machine's vagrant folder.
I tried another approach by going in the vagrant vm's default folder /home/vagrant and run 'touch hello.txt'. Then I checked the host machine's vagrant folder using Finder and nope, I don't see hello.txt file either.
Appreciate any helpful inputs.

I finally found it...
Inside the Vagrantfile file, look for the following config setting:
config.vm.synced_folder
And mine's actually set as:
config.vm.synced_folder ".", "/vagrant"
When I gone back to check the /vagrant (NOT /home/vagrant) folder in my vagrant vm, there i found the files that I placed in my host machine's vagrant folder.
Although I wonder what the "." means - but in the meantime, I'm happy I found what I needed :)

Related

Empty /vagrant folder after I power off the VM

I have a Vagrant VM using Virtualbox.
I have many files in my root folder which appear in /vagrant folder inside the VM.
When I power it off and restart it, the /vagrant folder is empty.
Why?
How are you powering the vm off and restarting?
It is vagrant who mounts that directory.
If you are doing that operations from VirtualBox directly it is not going to be mounted.

Vagrant : synchronised folder that is creating during provisionning error

I am trying to share a folder betwing my vagrant box and my host using this directive in Vagrantfile :
config.vm.synced_folder "./syncWithBox", "/var/www/html/"
The issue is that the /var/www/html/ folder is created during provisionning (installing apache2 server).
So when I vagrant up, there is an error because the /var/www folder does not exist before provisionning !
Is there a way to solve that ? How can I tell vagrant to perform folder sync after provionning ?
I saw a similar question here, but the answer is not exactly what I am looking for
This workaround works for me. I put the following command in an install.sh script and run it:
#!/bin/bash
vagrant plugin install vagrant-vbguest && vagrant up --no-provision
sed -i 's/#config.vm.synced_folder/config.vm.synced_folder/' Vagrantfile
vagrant halt && vagrant up --no-provision
vagrant provision
Install vbox addition with vagrant-vbguest plugin and Vagrant up the box without provisioning it
uncomment the synchronized folder directive using sed for example
stop the box and Vagrant it up without provisioning it : so the folders between host and guest are empty but synchronized
finally, provision the box

How do I package a vagrantfile so that it is used when 'vagrant init' is called on the box?

I know this is a stupid question, I'm still struggling to grok vagrant.
I run vagrant on a windows host, and I'm building Linux guest VMs using VirtualBox. My guest VM is running, and now I want to package it.
The Vagrant documentation says "A common misconception is that the --vagrantfile option will package a Vagrantfile that is used when vagrant init is used with this box. This is not the case. Instead, a Vagrantfile is loaded and read as part of the Vagrant load process when the box is used. For more information, read about the Vagrantfile load order."
Got it. But that's what I want to do! When I run "vagrant package --output myboxname.box", my carefully-crafted Vagrant file does not appear to be in the package. I test the box as follows (in Windows, after copying the new box):
cd \some_new_dir
vagrant box add myboxname.box --name boxname
vagrant init boxname
The new Vagrantfile is the generic vagrant version, with none of my changes.
When I
vagrant up
The vm comes up fine, but (not surprisingly) none of Vagrantfile directives have happened.
I know I'm missing something basic -- can someone please help me out?
Try copying the Vagrantfile from the directory you ran vagrant package in to the \some_new_dir directory. Then, without running vagrant init (because this will overwrite the Vagrantfile with an empty file), run vagrant up to use the Vagrantfile.

Distributing vagrant VM locally

I have set up a vagrant vm on my machine. (Virtualbox)
I would like to be able to share this VM amongst other machines however would like to avoid having to download the image repeatedly.
I tried Exporting the Appliance and copying the Vagrantfile folder onto a different machine, however when i tried to connect using vagrant ssh it could not find it. I assume this is because of non-matching UUID's. How can I go around this?
Vagrant version 1.6.3
The solution was to use Vagrant Package
vagrant package --base <Name Of VM on virtualbox>
This creates a package.box file in your current directory.
You then share that package.box file, and on the new computers you execute:
vagrant init package.box
in the directory where the Vagrantfile will be created

Ubuntu guest can't see Vagrantfile in Window's host project directory

I just installed Vagrant 1.4.3 on Windows 7 64-bit and created an Ubuntu 13.10 (Saucy) box using the following:
vagrant box add saucy64-20140226 http://cloud-images.ubuntu.com/vagrant/saucy/20140226/saucy-server-cloudimg-amd64-vagrant-disk1.box
vagrant init saucy64-20140226
After doing:
vagrant up
I SSH'ed to the vagrant box using Putty. Up to this point is fine, but when I do:
$ ls
in the /vagrant directory (on the Guest), I do not see my 'Vagrantfile' or any other files from the Host machine.
Also, any files created in the Guest's /vagrant directory do not show up in the Host's synced directory.
I noticed the following when the box/vm was starting up:
[default] The guest additions on this VM do not match the installed
version of VirtualBox! In most cases this is fine, but in rare cases
it can prevent things such as shared folders from working properly. If
you see shared folder errors, please make sure the guest additions
within the virtual machine match the version of VirtualBox you have
installed on your host and reload your VM.
After researching a little more, found that the following solves the issue:
https://github.com/dotless-de/vagrant-vbguest
Here's a more detailed post:
http://kvz.io/blog/2013/01/16/vagrant-tip-keep-virtualbox-guest-additions-in-sync/
Thanks very much to the folks who created the 'vagrant-vbguest' Vagrant plugin!!!

Resources