de-crob de-crob - 3 years ago 214
JSON Question

How to troubleshoot the code that makes up an Ansible plugin?

Currently, I am trying to troubleshoot an action plugin that calls other working Ansible modules to reuse the code, making the playbook for those modules a lot simpler to use.

Previously when testing the other smaller modules, if I couldn't uncover the error when running my test playbook, I would make a json file of the playbook's arguments and supply it to pdb like so:

python -m pdb /path/to/ ./test.json

With an action plugin, Ansible does far more set up than I am able to surmise from reading through the ActionBase files in the main Ansible repository, rendering my json tests unable to aid my diagnosis of the issue.

Using the Ansible debug features only steps through the various tasks and plays in the playbook, but not the underlying code. Embedding
import pdb;pdb.set_trace()
in the plugin/module doesn't help as running pdb when running a play causes halting, rather than an interactive debugger to appear.

Answer Source

You should enforce tty. This code works for me when debugging Ansible plugins:

import sys; sys.stdin = open('/dev/tty')
import pdb; pdb.set_trace()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download