How to upload configuration files using the shell provider?

Apart from installing applications like emacs on my guest machine, I would also like to upload some configuration files (e.g. to configure emacs for Clojure development). Sadly, Vagrant's documentation gives no clue about how to do this. I guess I'd have to put the configuration files into a shared folder and then copy them from the shared folder on the guest machine to the desired locations?


Solution 1:

You can use the "file" provisioner. It seems to be undocumented, but usage is simple. For example:

Vagrant.configure('2') do |config|
  # ...

  config.vm.provision :file do |file|
    file.source      = '~/.my.conf'
    file.destination = '/home/vagrant/.my.conf'
  end
end

First catch is that it is run as the ssh user ("vagrant" by default) without sudo, so you need to have write access to the directory on the VM. A workaround is to copy to a temporary location and then use a normal shell provisioner to copy/move it to right place.

Second issues is that target paths are not expanded correctly. So using ~ or $HOME most probably won't work as expected. (The source path on the other hand is expanded.)

Solution 2:

Yes, you should "put the configuration files into a shared folder and then copy them from the shared folder on the guest machine to the desired location".