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

4.4k Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

There is also another work around:

I created a nfs directory called shared and copied the install.sh file in the nfs directory and shared it to my vagrant box by adding the below snippet in the Vagrantfile

config.vm.synced_folder "shared", "/home/vagrant/shared"