How to debug Ansible issues?

后端 未结 7 1939
滥情空心
滥情空心 2020-12-08 04:26

Sometimes, ansible doesn\'t do what you want. And increasing verbosity doesn\'t help. For example, I\'m now trying to start coturn server, which co

7条回答
  •  醉话见心
    2020-12-08 05:12

    Here's what I came up with.

    Ansible sends modules to the target system and executes them there. Therefore, if you change module locally, your changes will take effect when running playbook. On my machine modules are at /usr/lib/python2.7/site-packages/ansible/modules (ansible-2.1.2.0). And service module is at core/system/service.py. Anisble modules (instances of AnsibleModule class declared at module_utils/basic.py) has log method, which sends messages to systemd journal if available, or falls back to syslog. So, run journalctl -f on target system, add debug statements (module.log(msg='test')) to module locally, and run your playbook. You'll see debug statements under ansible-basic.py unit name.

    Additionally, when you run ansible-playbook with -vvv, you can see some debug output in systemd journal, at least invocation messages, and error messages if any.

    One more thing, if you try to debug code that's running locally with pdb (import pdb; pdb.set_trace()), you'll most likely run into BdbQuit exception. That's because python closes stdin when creating a thread (ansible worker). The solution here is to reopen stdin before running pdb.set_trace() as suggested here:

    sys.stdin = open('/dev/tty')
    import pdb; pdb.set_trace()
    

提交回复
热议问题