我的烧瓶应用使用alembic来管理数据库迁移。在尝试使用Ansible部署应用程序时,当Ansible playbook遇到命令python manage.py db upgrade
时,它会遇到运行时错误,超出最大递归深度。错误讯息:
fatal: [host.ip]: FAILED! => {"changed": true, "cmd": "/home/deploy/venvs/app/bin/python
/var/www/app/manage.py db upgrade", "delta": "0:00:02.854134",
"end": "2016-04-11 15:59:32.656916", "failed": true, "rc": 1,
"start": "2016-04-11 15:59:29.802782",
"stderr": "INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
...
...
File \"/home/deploy/venvs/app/local/lib/python2.7/site-packages/sqlalchemy/
sql/elements.py\", line 3292, in _get_table
return self.__dict__['table']
RuntimeError: maximum recursion depth exceeded in cmp",
"stdout": "", "stdout_lines": [], "warnings": []}
当我在本地运行命令时,我没有收到任何错误,也没有在实际连接到远程计算机并运行相同命令时。我的app结构是:
my_app
|--my_app
|--migrations
|--versions
|--alembic.ini
|--env.py
|--README
|--script.py.mako
|--playbooks
|--tests
|--manage.py
|--settings.py
|--wsgi.py
示例Ansible playbook deploy.yml
如下:
- name: install dependencies into a new virtualenv
pip: requirements={{ app_dir }}/requirements.txt
virtualenv={{ venv_dir }}
- name: create .env file in base directory of the app from template
template: src=env.j2
dest={{ app_dir }}/.env
- name: sync the database tables between Flask and PostgreSQL
shell: ". {{ app_dir }}/.env; {{ venv_python }} {{ app_dir }}/manage.py db upgrade"
变量赋值的vars
文件如下:
wsgi_env_vars: {
APP_ENV: 'prod',
}
使用相应的env.j2
模板文件:
#!/bin/bash
{% for k, v in wsgi_env_vars.iteritems() %}
export {{ k }}="{{ v }}"
{% endfor %}
尝试了不同的方法来解决错误,包括在ansible中将默认shell从sh更改为bash,但没有任何帮助。任何人都可以帮助找出错误吗?