The config.vm.provision
script is copied to /tmp, if that is executed on a noexec mounted filesystem I get this error:
==> default: bash: line 2: /tmp/vagrant-shell: Permission denied
A suggested solution: treat the shell script as an input for bash:
bash /tmp/vagrant-shell
Source file: vagrant/plugins/provisioners/shell/provisioner.rb
Hi @bbaassssiiee
Thank you for opening an issue. Unfortunately we cannot just assume bash. Fortunately, the recommended work around is listed in the docs: https://www.vagrantup.com/docs/provisioning/shell.html
To run a script already available on the guest you can use an inline script to invoke the remote script on the guest.
Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "/bin/sh /path/to/the/script/already/on/the/guest.sh" end
The recommended pattern is to upload the script using a file provisioner and then manually execute it with your desired interpreter. Thanks! :smile:
Hi @sethvargo,
how should your workaround work? Problem is as follows: If you upload the file with a file provisioner, I' m not able to upload it with execute rights from a windows host. Therefore I can't use the shell provisioners path function to execute the script. On the other hand I can not use your provided inline: variant, because that just create /tmp/vagrant-shell with the content "/bin/sh /path/to/the/script/already/on/the/guest.sh" and tries to execute it. Of course the execute then fails, because /tmp is still noexec.
Is it somehow possible to tell the shell provisioner that it should create the tmp-file in a specific path?
Regards
Raskil
In case anyone else come across this, you need to use the upload_path option to point the script somewhere else other than /tmp.
I use something like this:
config.vm.provision "vagrant preflight", type: "shell",
path: "scripts/preflight.sh",
upload_path: '/opt/preflight.sh',
args: "#{username}"
Most helpful comment
In case anyone else come across this, you need to use the upload_path option to point the script somewhere else other than /tmp.
I use something like this: