How to get more usable error messages from ansible-playbook?

python ansible

915 просмотра

2 ответа

ansible-playbook gives me errors that look like this:

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"]}

Of course I could copy this and paste it into ipython to get a more usable view on things, i.e.

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"]}

But I'd like ansible to do that for me. How can I do that?

This is related but doesn't look like solution to my problem: Ansible playbook shell output

Автор: fifi finance Источник Размещён: 08.11.2019 11:18

Ответы (2)


2 плюса

Increase the verbosity. Add -vvvv at the end of ansible-playbook command. It will set the verbosity to 4 and that much logs are good enough most of the time.

Автор: deosha Размещён: 20.08.2016 05:17

1 плюс

Ansible allows you to control its output by using callback plugins and provides a few optional callbacks out of the box.

To configure them simply set the callback_plugs option in ansible.cfg:

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

To get Ansible to print the newlines rather than render them as \ns you could develop your own callback or simply use the human_log callback plugin developed by Cliffano Subagio.

For Ansible 2 compatibility (the plugin system was rewritten in the version upgrade from Ansible 1.x) an equivalent was written by n0ts.

Автор: ydaetskcoR Размещён: 20.08.2016 03:42
Вопросы из категории :
32x32