Home..." @app.route("/health") " /> Home..." @app.route("/health") " /> Home..." @app.route("/health") "/>

Troubleshooting access to Flask app in Vagrant guest

134 Views Asked by At

I have a toy Flask app:

from flask import Flask

app = Flask(__name__)

@app.route("/home")
def home():
    return "<h1>Home...</h1>"

@app.route("/health")
def health():
    return "<h1>Healthy</h1>"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000, debug=True)

.. which is being provisioned using Ansible on a Vagrant guest machine with the following Vagrantfile:

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

Vagrant.configure(2) do |config|
  config.vm.box = "geerlingguy/centos7"
  config.vm.provision "ansible_local" do |ansible|
    ansible.playbook = "playbooks/run.yml"
    ansible.tags = "install"
  end
  config.vm.network "forwarded_port", guest: 5000, host: 5000
  config.vm.provider "virtualbox" do |v|
     v.memory = 2048
     v.cpus = 1
  end
end

If I vagrant ssh to the guest and launch the flaskapp in with the following:

export FLASK_APP='/flaskapp/app.py'
export FLASK_ENV='development'
cd  /flaskapp
python3 -m flask run

I can curl 127.0.0.1:5000/home with a successful response.

However from the Vagrant host (i.e. not the guest where the flask app is running), I cannot access http://localhost:5000/home. Accessing localhost:5000/home (or 127.0.0.1:500/home) is:

The connection was reset

The connection to the server was reset while the page was loading.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer’s network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

I'm using Windows 10, and the guest VMs network config looks like this:

Guest network config

I have tried assigning static ip or assigning an ip dynamically but I cannot access. I am not sure if it's something that I need to add to the /etc/hosts file...

Can anyone help to identify the issue here and how can I debug this kind of problem?

0

There are 0 best solutions below