Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share a single file in vagrant

How do I share a single file, instead of sharing a whole folder like

config.vm.synced_folder "host/folder", "box/folder"

?

In other words is there a way to have something like:

config.vm.synced_folder "host/folder/file.conf", "box/folder/file.conf"
like image 487
Thorben Croisé Avatar asked Apr 01 '15 15:04

Thorben Croisé


2 Answers

You can use the file provisioner to do this:

Vagrant.configure("2") do |config|
  # ... other configuration

  config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
end
like image 102
slm Avatar answered Oct 19 '22 04:10

slm


The accepted answer (by cdmo) didn't work for me, but was close and led me to the right solution, so cheers. To copy just one file I needed to change it to:

config.vm.synced_folder "c:/hostpath/", "/guestpath/", type: "rsync",
  rsync__args: ["-r", "--include=file.text", "--exclude=*"]

Mind the arguments and their order, -r MUST be present and --include MUST precede --exclude.

If needed, instead of -r option you may use -a option which combines -r with several other options for preservation of permissions, ownership etc. (see rsync help).

My testing configuration: Vagrant 2.0.2/Win10/VirtualBox 5.2.6

like image 29
jedik Avatar answered Oct 19 '22 06:10

jedik