Kit Sunde
Kit Sunde

Reputation: 37095

Can I configure Vagrant to setup a synced folder only if it exists on the host?

For our developers ~/Development/framework_repo is normally available on the host, but for our designers it wouldn't be. Is it possible to conditionally configure a synced folder depending on it's availability on the host?

Upvotes: 14

Views: 3853

Answers (2)

BrianC
BrianC

Reputation: 10721

Since the Vagrantfile is a Ruby script, you could check for the presence of the directory with File.directory(), and enable the shared folder only if needed.

For example:

Vagrant.configure("2") do |config|
  if File.directory?(File.expand_path("~/Development/framework_repo"))
    config.vm.synced_folder "~/Development/framework_repo", "/guest/path"
  end
end

Upvotes: 25

kkamil
kkamil

Reputation: 2595

You can try using vagrant conditional environments. Additional reading here. Generally you can create a script that will be run before execution of vagrant up. It will test your environment and set proper ENVs that will be further use by vagrant.

Upvotes: 1

Related Questions