2016-08-20 50 views
0

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

你應該永遠不會看到這樣的錯誤。 Ansible項目在進行堆棧跟蹤時認爲它是一個錯誤,而不是用更易於用戶使用的錯誤捕獲錯誤。在他們的GitHub上提出問題。 – smiller171

回答

1

Ansible允許您使用callback plugins來控制它的輸出,並提供了一些可選的回調out of the box

配置它們簡單地設置callback_plugs optionansible.cfg

callback_plugins = ~/.ansible/plugins/callback:/usr/share/ansible/plugins/callback 

要獲得Ansible打印換行,而不是使他們爲\n是你可以開發自己的回調或簡單地使用所制定的human_log回調插件Cliffano Subagio

對於Ansible 2的兼容性(插件系統從Ansible 1.x版本升級改寫而來),等效文件爲n0ts

1

增加詳細程度。在ansible-playbook命令的末尾添加-vvvv。它會將詳細程度設置爲4,並且大多數日誌都足夠好。

相關問題