Vagrantfile: Disabling synced folders for one provider, but not another - vagrant

I have been using Vagrant with VirtualBox for local development. Now, I want to deploy to Azure (question would be same with AWS).
When working locally with VirtualBox, it's awesome to have the synced folder. But I definitely don't want a synced folder for the cloud VM. So, how can I have it enabled for the former but disabled for the latter?
A snippet of my vagrantfile is below; however this doesn't seem to have any effect. Appreciate any pointers.
Vagrant.configure('2') do |config|
config.vm.synced_folder ".", "/vagrant"
# …
config.vm.provider :azure do |azure, override|
override.vm.synced_folder ".", "/vagrant", disabled: true
# …
End
# …
end
I've also tried initially disabling the synced folder, and then enabling it only for VirtualBox - but Azure still prompts for username/password and attempts to create an SMB share.
Update: Even if I disable it in the main section, and don't touch it for Azure, it still tries to create a SMB share, and complains that it can't find my machine (my laptop is behind NAT).

It turns out that the default synced folder was indeed being disabled correctly.
However, the Chef provisioner was being used, and behind the scenes this also uses synced folders! The solution therefore is to use a Chef server, or as I chose - to do everything via a shell provisioner.
Hope this question helps someone encountering this problem in the future.

I had the same problem with SMB synced folders not staying disabled even though I hade the correct lines to disable.
My problem was also caused by chef enabling synced folders again. I solved my problem by adding the chef.synced_folder_type = "rsync" to the chef config block:
config.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "rsync"
[...more chef config...]
end

Related

Default shared folder in vagrant not visible

I have a problem with synced folder in Vagrant. My config is really simple:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder ".", "/vagrant"
end
Vagrant usually creates /vagrant folder automatically on start - this time it did not happen so I've done it manually.
But when I create a file in my host system - it's not visible in guest. Any ideas why?
I've succesfully created a similar configuration with:
config.vm.box = "hashicorp/precise64"
but it's a little bit outdated and I want to use Ubuntu 16.04.
Is it a problem with my config, vagrant box, or something else?
You could try: Make sure you have the latest version of Vagrant and VB. Restart your computer (I know, but it sometimes does help in these cases). Try again in a new directory (or vagrant destroy if you want to start fresh and don't need any old content), i.e., make sure the old .vagrant directory isn't there.
vagrant up or vagrant reload and check again.
Assuming you are using VirtualBox, make sure you don't have any "Guest Additions" issues. You could try https://github.com/dotless-de/vagrant-vbguest
If it still doesn't work, check the --debug output again as #frédéric-henri mentioned -- look for all mentions of your share name. Also "/vagrant" isn't always the default, it depends on the box. Sometimes it's "/vagrant_data" or others, but if you specify "/vagrant" in the config -- that should work.

vagrant - Vagrantfile: sync multiple folders

I have tried the following to sync multiple folders from host to guest machine.
But only one folder is getting synced, the later one.
config.vm.synced_folder "host/site1", "/var/www/site1"
config.vm.synced_folder "host/site2", "/var/www/site2"
In newest virtualbox and vagrant versions this is improved and work without problems...

Vagrant workflow

Hi i was trying to understand what exactly is done when running
vagrant up
my reason for that is that in my case we need to install a lot of utilities.
i.e Version control tools, build tools, ide, etc...
which takes a lot of time.
so actually i wanted a 'box' with all those tools.
After i have clean environment and got all tools, i would like to make CI for our product.
If i will reinstall all utilities it should take a lot of time. so what i am actually need is just installing and testing our product.
How should i handle that ??
create my own box? does the command reinstall all utilities when we make CI ??
what i actually need are 2 processes :
1.installing utilities for my vm. (once a month)
2.test our product (each commit\push to version control)
how can i achieve that ?
For the first time, vagrant up will create a new VM for you, pulling the box image if needed, and it will provision it with what you configured in the Vagrantfile. In the provision configuration, you can tell Chef or Puppet to install all the utilities and tools that you need.
When you suspend or halt the VM, the next time you do a vagrant up it will only bring that VM back up. It will not install or try to provision it again.
You can force it with vagrant up --provision or just vagrant provision.
This usually works well in a development environment.
In a CI environment, it may not be possible to have the VM already provision, forcing you to run the provisioning step every time. You can achieve what you need packaging your own box with the tools already installed, essentially creating a golden or base image.
Just be extra careful so that the CI environment don't differ for what you have in production.
All depend on the setting in Vagrantfile
you have modules folder to put all puppet modules, manifests folder with site.pp and Vagrantfile as below under same place.
Give you a sample of Vagrantfile I used mostly.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box "
config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
puppet.manifests_path = "manifests"
puppet.manifest_file = "site.pp"
end
config.vm.define :www do |config|
config.vm.host_name = "www.example.com"
config.vm.network :private_network, ip: "192.168.1.2"
end
config.vm.define :db1 do |config|
config.vm.host_name = "db1.example.com"
config.vm.network :private_network, ip: "192.168.1.4"
end
end
So after run vagrant up www or vagrant up db1 it will start the box with puppet apply directly. You can understand this way as puppet masterless
Vagrant just make the box up running from linux image defined in config.vm.box_url as a simple fresh linux box, and mount your local folder to new box's /vagrant folder, then hand over to puppet. How the server to be provisioned, will be depended on site.pp (define applications on each node) and puppet modules. The command is similar as
puppet apply --modulepath /vagrant/module /vagrant/manifests/site.pp
So if your puppet modules are fine, your new box will automatically have all utilities and products installed. Then you run vagrant ssh www or vagrant ssh db1, you can login it and start working.
You can put your local folder with moduels, manifests folders and Vagrantfile to version control (such as git). So developers can clone the git repository to their own computer easily.

How to disable shared folders for puppet provisioner in Vagrant

I want to disable creating and mounting any shared folders for vagrant VMs.
I've found a way to disable sharing main /vagrant folder and instead uploading necessary files, but not able to find a way to disable shared folder creation for puppet provisioner.
I want to upload puppet files to VM instead of sharing from my host OS. Is it possible to do?
You could use rsync synced folder type (the docs):
Vagrant.configure("2") do |config|
config.vm.provision "puppet" do
puppet.synced_folder_type = "rsync"
# ...
end
end

Why is Vagrant hosting my project directory on the guest machine?

For a project with a file /foo/bar/Vagrantfile, Vagrant shares/syncs /foo/bar on the host machine as /vagrant on the guest machine.
Why is it doing this? It appears to be undesirable: the whole point is achieving isolation, but this sharing destroys isolation: a buggy VM can delete my project directory, and my tinkering with my project can affect the VM.
So, what is the point of this? Is it necessary for something I've overlooked?
Vagrant by default sync the project directory (where Vagrantfile resides) with /vagrant within the guest.
If it is NOT desired, it can be disabled by explicitly disable the synced folder config in Vagrantfile and then a vagrant reload is needed.
config.vm.synced_folder ".", "/vagrant", disabled: true
If one-off or manual sync is required, use the new rsync type added in vagrant 1.5.x.

Resources