Vagrant: `path` for shell provisioner does not exist on the host system

Created on 11 Apr 2018  ยท  9Comments  ยท  Source: hashicorp/vagrant

Hello everyone. I have been looking around on what I might be doing wrong but as of now I cannot distribute a box with a provisioner script. Please ask me for more details if needed.

Vagrant version

Vagrant 2.0.3

Host operating system

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:    16.04
Codename:   xenial

But also happens on Windows just the same.

Guest operating system

Same as above

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"
  config.vm.provision "shell", path: "script.sh"
end

Debug output

out.txt

Expected behavior

I have packaged my box with: vagrant package --include script.sh --vagrantfile Vagrantfile, uploaded it to https://app.vagrantup.com/niosus/boxes/TestBox and then tried to load from another folder:

vagrant init niosus/TestBox
vagrant up

I was expecting the box to load.

Actual behavior

vagrant up throws an error:

There are errors in the configuration of this machine. Please fix
the following errors and try again:

shell provisioner:
* `path` for shell provisioner does not exist on the host system: /tmp/Vagrant/script.sh

References

Are there any other GitHub issues (open or closed) that should be linked here?
For example:

  • #1046
  • This StackOverflow question
  • Chassis/Chassis#314
  • fideloper/Vaprobash#30
question

Most helpful comment

Thanks @chrisroberts I can confirm that this works. However, at this state the documentation here is broken or at least misleading. It seems that the proper solution would be to actually expand the file path just like in your solution in the background. So that I could still use syntax from the documentation and at the same time could use --include flag when packaging the box. An easier solution would be to just update the documentation page to account for the fact, that what is currently suggested will not work with --include. What do you think?

All 9 comments

Hi there,

I tried to download your box to inspect it, but it looks like it only has an inline script defined for provisioning. Is the non-functional box still available for inspection?

Ah, yes, sorry. I needed it to be done, so I have changed to having the script inline. Would you want a small reproducible example? I can compile it within today or tomorrow.

@chrisroberts I have updated the issue with a smaller test box that reproduces the issue exactly

@niosus perfect, thanks!

Sure, happy to help in solving this. Please tell me if you need anything else.

Okay, got the new box and was able to reproduce the path error you were encountering. The underlying cause is that the path is expanded from the vagrant working directory. Updating the script path to use an expanded path based on the location of the custom Vagrantfile makes things work as expected:

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/xenial64"

  dir = File.expand_path("..", __FILE__)
  puts "DIR: #{dir}"

  config.vm.provision "shell", path: File.join(dir, "script.sh")

end

(the puts is there just to provide some output on up showing it getting the correct location).

Cheers!

Thanks @chrisroberts I can confirm that this works. However, at this state the documentation here is broken or at least misleading. It seems that the proper solution would be to actually expand the file path just like in your solution in the background. So that I could still use syntax from the documentation and at the same time could use --include flag when packaging the box. An easier solution would be to just update the documentation page to account for the fact, that what is currently suggested will not work with --include. What do you think?

check if you have enough space for vagrant file to get downloaded. I Hope there isnt much space required for it to get downloaded .

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings