Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run python script on vagrant up

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?

like image 782
Yaron Idan Avatar asked Mar 12 '23 13:03

Yaron Idan


2 Answers

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
like image 146
Frederic Henri Avatar answered Mar 19 '23 05:03

Frederic Henri


If you want to start app when the machine start, you can do that:

  1. move your python app code directory to the Vagrantfile's directory

  2. Config the Vagrantfile like that:

    config.vm.provision "shell", inline: <<-SHELL
      python /vagrant/<your python app code directory>/app.py
    SHELL
    
like image 41
wang aaron Avatar answered Mar 19 '23 06:03

wang aaron