Vagrant : synchronised folder that is creating during provisionning error - vagrant

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

Related

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

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 :)

Vagrant command doesn't work without Sudo

I have installed homestead with Vagrant in my MacOS. I have installed all with Virtual Box, but when i try to use vagrant command in my terminal for running Virtual Machine appear this error:
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.
I try with sudo vagrant up and it work but is not the best choice.
Anyone can help me?
There's a screenshot of the terminal Error:
Terminal Error with command vagrant up and vagrant ssh.
Try deleting .vagrant directory
rm -r .vagrant
I suspect you copied or moved project folder from one place to another.
Alternatively you need to update the creator_uid file in .vagrant/. Check out this blog post.

No config.yaml file when installing Vagrant box

So I downloaded this box: https://atlas.hashicorp.com/ncaro/boxes/php7-debian8-apache-nginx-mysql
I then go to my project folder and I execute the following commands:
vagrant init ncaro/php7-debian8-apache-nginx-mysql; vagrant up --provider virtualbox
But I dont see config.yaml in my directory. Why is that?
Best Regards

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.

No synced vagrant folder to be found

I am trying to work through the "Getting Started" section at the vagrant site. I run through the two commands they show:
$ vagrant init hashicorp/precise32
$ vagrant up
All seems to go well. I then run these two commands:
$ vagrant ssh
$ lsb_release -a
The result shows I'm running on Ubuntu 12.04, precise. So far so good.
However, when I do an 'ls' the only thing in the directory is a postinstall.sh file. I thought I should have been in the same directory as the Vagrantfile.
Sorry for such a newbie question. I'm sure its something basic I messed up.
I'm doing this on an Ubuntu 14.10 box with Virtualbox 4.3.22 and Vagrant 1.7.2 installed.
Thanks
By default, Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant on the guest machine.

Resources