4

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?

2 Answers 2

6

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
Sign up to request clarification or add additional context in comments.

Comments

1

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
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.