# How to debug/test ansible module. Python interactive mode (pdb)

**URL:** <https://forum.ansible.com/t/how-to-debug-test-ansible-module-python-interactive-mode-pdb/25081>\
**Category:** Ansible Project\
**Created:** [July 25, 2017, 2:12pm UTC](https://forum.ansible.com/t/how-to-debug-test-ansible-module-python-interactive-mode-pdb/25081 "2017-07-25T14:12:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![russell\_choudhury](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@russell\_choudhury](https://forum.ansible.com/u/russell_choudhury)\
**Post date:** [July 25, 2017, 2:12pm UTC](https://forum.ansible.com/t/how-to-debug-test-ansible-module-python-interactive-mode-pdb/25081/1 "2017-07-25T14:12:07Z")

</div>

Hi, I want to be able to go into interactive mode while creating a module. To do this I am adding the following line to my python code:

import pdb; pdb.set\_trace()

when I run my ansible playbook with the following line:  
ansible-playbook -i hosts helloworld.yml -vvv

I get this error:

The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_fDi5pe/ansible\_module\_helloworld.py”, line  
5, in   
def main():  
File “/tmp/ansible\_fDi5pe/ansible\_module\_helloworld.py”, line  
5, in   
def main():  
File “/usr/lib/python2.7/bdb.py”, line 49, in trace\_dispatch  
return self.dispatch\_line(frame)  
File “/usr/lib/python2.7/bdb.py”, line 68, in dispatch\_line  
if self.quitting: raise BdbQuit  
bdb.BdbQuit

fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “Traceback (most recent call last):\n Fil  
e "/tmp/ansible\_fDi5pe/ansible\_module\_helloworld.py", line 5,  
in \n def main():\n File "/tmp/ansible\_fDi5pe/ans  
ible\_module\_helloworld.py", line 5, in \n def main(  
):\n File "/usr/lib/python2.7/bdb.py", line 49, in trace\_dis  
patch\n return self.dispatch\_line(frame)\n File "/usr/lib/  
python2.7/bdb.py", line 68, in dispatch\_line\n if self.quit  
ting: raise BdbQuit\nbdb.BdbQuit\n”,  
“module\_stdout”: “\> /tmp/ansible\_fDi5pe/ansible\_module\_hell  
oworld.py(5)()\n → def main():\n(Pdb) \*\*\* NameError: na  
me ‘false’ is not defined\n(Pdb) \n”,  
“msg”: “MODULE FAILURE”,  
“rc”: 0  
}

---

<div class="post-metadata">

**Author:** ![Martin\_Krizek](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Martin\_Krizek](https://forum.ansible.com/u/Martin_Krizek)\
**Post date:** [July 25, 2017, 2:18pm UTC](https://forum.ansible.com/t/how-to-debug-test-ansible-module-python-interactive-mode-pdb/25081/2 "2017-07-25T14:18:49Z")

</div>

Hi,

Using epdb instead of pdb should do the trick, so "import epdb;  
epdb.serve()" and then you connect via "epdb.connect()" from a python  
shell. See [https://pypi.python.org/pypi/epdb/](https://pypi.python.org/pypi/epdb/).

Martin

---

<div class="post-metadata">

**Author:** ![russell\_choudhury](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@russell\_choudhury](https://forum.ansible.com/u/russell_choudhury)\
**Post date:** [July 25, 2017, 2:39pm UTC](https://forum.ansible.com/t/how-to-debug-test-ansible-module-python-interactive-mode-pdb/25081/3 "2017-07-25T14:39:07Z")

</div>

thanks soo much for the fast reply… it worked 😃

‘import epdb; epdb.set\_trace()’ seems to work aswell
