I'm trying to run a vagranfile that will result in a running python flask app. I've tried using this as the last command to achieve this -
config.vm.provision :shell, :path => "python app.py"
But it resulted with the following error -
*
pathfor shell provisioner does not exist on the host system: /Users/*****/code/app-vagrant/python app.py
I understand that the script is trying to run this command from the host machine, how do I make Vagrant run the script on the vagrant machine launched?
you have 2 options to run a script using the vagrant shell provisioner you must pass either the inline
or path
argument:
inline (string) - Specifies a shell command inline to execute on the remote machine.
path (string) - Path to a shell script to upload and execute. It can be a script relative to the project Vagrantfile or a remote script (like a gist).
so when you pass :path => "python app.py"
the system tries to find a script named python app.py
on your host.
replace using inline
argument and it will achieve what you want
config.vm.provision :shell, :inline => "python app.py"
note: provisioner are run as root
user by default, if you want to change and run it as vagrant
user:
config.vm.provision :shell, :inline => "python app.py", :privileged => false
If you want to start app when the machine start, you can do that:
move your python app code directory
to the Vagrantfile's directory
Config the Vagrantfile like that:
config.vm.provision "shell", inline: <<-SHELL
python /vagrant/<your python app code directory>/app.py
SHELL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With