Vagrant: config.vm.provision does not allow me to copy a file to etc/nginx/conf.d? Vagrant: config.vm.provision does not allow me to copy a file to etc/nginx/conf.d? nginx nginx

Vagrant: config.vm.provision does not allow me to copy a file to etc/nginx/conf.d?


As the error message suggest and also from the documentation:

The file uploads by the file provisioner are done as the SSH or PowerShell user. This is important since these users generally do not have elevated privileges on their own. If you want to upload files to locations that require elevated privileges, we recommend uploading them to temporary locations and then using the shell provisioner to move them into place.

So the vagrant user(if not modified) is used to scp the file but you can't access /etc/ with it.

To make it work you need to upload it to a temporary location and then use a shell provisioner to move it to target directory:

config.vm.provision "file",   source: "./bolt.local.conf",   destination: "/tmp/bolt.local.conf"config.vm.provision "shell",  inline: "mv /tmp/bolt.local.conf /etc/nginx/conf.d/bolt.local.conf"

This work because the privileged option is true by default on shell provisioners. But it is a bit convoluted to have two provisioners just to copy a configuration file, right ?

Well if the file is already inside your share folder you can just use a shell provisioner to copy it in the nginx directory so you'll end up with something like this:

# This is the default and serve just as a reminderconfig.vm.synced_folder ".", "/vagrant"config.vm.provision "shell",  inline: "cp /vagrant/bolt.local.conf /etc/nginx/conf.d/bolt.local.conf"