Question

I'm working through a guide to deploying Flask app using Vagrant and Ansbile (https://github.com/nickhs/flask_skeleton) but keep hitting an error which I don't know how to fix.

I run the following ... $ vagrant up db

... which goes through a fair few steps before an error which I can't find any answer to.

These are the steps completed...

[db] Running provisioner: ansible...

PLAY [dbservers] ************************************************************** 

GATHERING FACTS *************************************************************** 

TASK: [update apt] ************************************************************ 
changed: [192.168.100.20]

TASK: [install base packages] ************************************************* 
changed: [192.168.100.20] => (item=libpq-dev,python-dev,python-setuptools,git,libevent-dev,python-psycopg2)

TASK: [install pip] *********************************************************** 
changed: [192.168.100.20]

TASK: [add env variables] ***************************************************** 
changed: [192.168.100.20]

TASK: [install db server packages] ******************************************** 
changed: [192.168.100.20] => (item=postgresql,postgresql-contrib)

TASK: [update postgres db configuration] ************************************** 
changed: [192.168.100.20]

TASK: [update postgres client configuration] ********************************** 
changed: [192.168.100.20]

TASK: [link /vagrant to /srv/flask_skeleton] ********************************** 
changed: [192.168.100.20]

TASK: [install dependencies] ************************************************** 
changed: [192.168.100.20]

NOTIFIED: [source env variables] ********************************************** 
ok: [192.168.100.20]

NOTIFIED: [restart postgresql] ************************************************ 

PLAY [dbservers] ************************************************************** 
TASK: [create database user] ************************************************** 
TASK: [create database] ******************************************************* 

NOTIFIED: [build database] **************************************************** 
failed: [192.168.100.20] => {"item": "", "rc": 1}
stdout: Traceback (most recent call last):
  File "/srv/flask_skeleton/createdb.py", line 1, in <module>
    from app import db
ImportError: cannot import name db


PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/var/tmp/ansible/vagrant-dbserver.retry

192.168.100.20             : ok=14   changed=12   unreachable=0    failed=1   

Can anyone point me in the right direction?

Était-ce utile?

La solution

Looking at the lines in app.py:

app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')

if app.config['SQLALCHEMY_DATABASE_URI']:
    db = SQLAlchemy(app)

If you don't have the DATABASE_URL defined, then there will be no 'db' variable created which then cannot be imported in the createdb.py module. Can you check if you indeed have a value for os.environ.get('DATABASE_URL') ?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top