ansible-playbook
给出了如下错误:
fatal: [test.example.com]: FAILED! => {"changed": false, "cmd": "./manage.py migrate --noinput
--pythonpath=/srv/virtualenv/myapp/bin/python3", "failed": true, "msg": "\n:stderr: Traceback (most recent call last):\n File \"./manage.py\", line 10, in <module>\n execute_from_command_line(sys.argv)\n File \"/srv/virtualenv/myapp/lib/python3.5/site-packages/django/core/management/__init__.py\", line 354, in execute_from_command_line\n utility.execute()\n File \"/srv/virtualenv/myapp/lib/python3.5/site-packages/django/core/management/__init__.py\", line 303, in execute\n settings.INSTALLED_APPS\n File \"/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py\", line 48, in __getattr__\n self._setup(name)\n File \"/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py\", line 44, in _setup\n self._wrapped = Settings(settings_module)\n File \"/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py\", line 92, in __init__\n mod = importlib.import_module(self.SETTINGS_MODULE)\n File \"/srv/virtualenv/myapp/lib/python3.5/importlib/__init__.py\", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n File \"<frozen importlib._bootstrap>\", line 986, in _gcd_import\n File \"<frozen importlib._bootstrap>\", line 969, in
_find_and_load\n File \"<frozen importlib._bootstrap>\", line 956, in _find_and_load_unlocked\nImportError: No module named 'myapp.settings'\n", "path": "/srv/virtualenv/myapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "state": "absent", "syspath": ["/tmp/ansible_OoxaWI", "/tmp/ansible_OoxaWI/ansible_modlib.zip", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
当然我可以将其复制并粘贴到ipython
中以获得更实用的观点,即
fatal: [test.example.com]: FAILED! => {"changed": false, "cmd": "./manage.py migrate --noinput --pythonpath=/srv/virtualenv/myapp/bin/python3", "failed": true, "msg": "
:stderr: Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/srv/virtualenv/myapp/lib/python3.5/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/srv/virtualenv/myapp/lib/python3.5/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/srv/virtualenv/myapp/lib/python3.5/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/srv/virtualenv/myapp/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'myapp.settings'
", "path": "/srv/virtualenv/myapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "state": "absent", "syspath": ["/tmp/ansible_OoxaWI", "/tmp/ansible_OoxaWI/ansible_modlib.zip", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
但我希望ansible
为我这样做。我怎么能这样做?
这是相关的,但看起来不像我的问题的解决方案:Ansible playbook shell output
答案 0 :(得分:2)
增加冗长度。在ansible-playbook命令的末尾添加-vvvv
。它会将详细程度设置为4,并且大部分时间内的日志都很好。
答案 1 :(得分:1)
Ansible允许您使用callback plugins控制其输出,并提供一些可选的回调out of the box。
要配置它们,只需在ansible.cfg
中设置callback_plugs
option:
callback_plugins = ~/.ansible/plugins/callback:/usr/share/ansible/plugins/callback
要让Ansible打印换行符而不是将其渲染为\n
,您可以开发自己的回调,或者只使用human_log
开发的Cliffano Subagio回调插件。
对于Ansible 2兼容性(插件系统在Ansible 1.x的版本升级中重写),等效内容由n0ts编写。