Reputation: 12870
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"
Upvotes: 9
Views: 5917
Reputation: 1244
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
Upvotes: 5
Reputation: 12870
As Benjamin Mosior explained, you can only synchronise a whole folder.
As a workaround, I ended up synchronising the whole folder to a temporary folder and in a later step creating a symlink where I need it to the single file inside this temporary folder.
Upvotes: 0
Reputation: 16416
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
Upvotes: 4
Reputation: 1309
Use the include
flag in your rsync args array:
config.vm.synced_folder "host/folder/", "box/folder/", type: "rsync",
rsync__args: ["--include=file.conf"]
Upvotes: 4
Reputation: 81
You can't synchronize a single file. But maybe you can achieve the same effect by synchronizing the folder using RSync with the rsync__exclude
option:
rsync__exclude
(string or array of strings) - A list of files or directories to exclude from the sync. The values can be any acceptable rsync exclude pattern.
Vagrant by default utilizes the file/folder synchronization mechanisms offered by the provider technologies (e.g., VirtualBox, VMWare, etc.). If the providers can't do synchronization on a per-file basis, then Vagrant can't either. Vagrant can also use NFS, RSync, or SMB for file synchronization. However, looking at the code, it would appear that each expects the per-folder paradigm.
Another possibility is to use one of the provisioning options to selectively synchronize the appropriate file(s). If you want to take the easy way out you could use the shell provisioner to just copy the file you need. For something more interesting, this is a reasonable guide to getting started with Puppet in Vagrant, and you might be interested in the puppet file
Type.
Upvotes: 2