Search code examples
rubyvagrantprovisioning

cp: cannot stat ‘path/file’: No such file or directory


I try to copy a file from host to vagrant box via vagrant provisioning:

command = "cp #{File.join(Dir.pwd,'install.sh')} /home/vagrant/"  # /home/user/vagrant/install.sh  /home/vagrant
config.vm.provision :shell, :inline => command

but then I get:

cp: cannot stat ‘/home/user/vagrant/install.sh’: No such file or directory
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!


Stderr from the command:
cp: cannot stat ‘/home/user/vagrant/install.sh’: No such file or directory

The file is located in the same directory as the Vagrantfile and I can access the file on the mentioned path


Solution

  • The shell provisioner runs the given command on the vagrant box, not on the host system.

    Since the host directory with the Vagrantfile (and, in this case, your install.sh) is mounted as /vagrant in the vm, changing the command to cp /vagrant/install.sh /home/vagrant should to do trick.