In a Vagrant setup, I have to upload a couple of files from the host to the guest during the provisioning phase.
In https://docs.vagrantup.com/v2/provisioning/file.html I can see how to upload a single file, from a source to a destination, but how can I upload multiple files or a folder structure?
NOTE: I know I can do that using the shell provisioner, but in this particular case a set of file uploads would be more appropriate.
You would need a separate config.vim.provision
section for each file. You can add multiple of those sections to your Vagrantfile
, like this:
config.vm.provision :file do |file|
file.source = "/etc/file1.txt"
file.destination = "/tmp/1.txt"
end
config.vm.provision :file do |file|
file.source = "/etc/file2.txt"
file.destination = "/tmp/2.txt"
end
Output:
[default] Running provisioner: file...
[default] Running provisioner: file...
You see it is executing both provisioning actions. You can verify the file presence inside the virtual machine:
vagrant ssh -- ls -al /tmp/{1,2}.txt
-rw-r--r-- 1 vagrant vagrant 4 Aug 27 08:22 /tmp/1.txt
-rw-rw-r-- 1 vagrant vagrant 4 Aug 27 08:22 /tmp/2.txt