# Debugging Ansible with epdb

**URL:** <https://forum.ansible.com/t/debugging-ansible-with-epdb/15448>\
**Category:** Ansible Developer\
**Created:** [June 12, 2014, 6:13am UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448 "2014-06-12T06:13:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![howachen](https://avatars.discourse-cdn.com/v4/letter/h/54ee81/32.png) [@howachen](https://forum.ansible.com/u/howachen)\
**Post date:** [June 12, 2014, 6:13am UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448/1 "2014-06-12T06:13:17Z")

</div>

Hello,

I continue my post at [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/ansible-project/wuxFggq5UAw)

I have tried to insert a break point in my module, e.g.

import epdb

# …

def some\_function():  
x = some\_random\_object.something\_interesting()  
epdb.st()

And I execute the command via: ansible --forks 1 --module-path . localhost -m test -a ‘’

But I cannot see the interactive shell and seems like it is hang-ed.

Any idea?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 12, 2014, 1:48pm UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448/2 "2014-06-12T13:48:33Z")

</div>

Are you running the module remotely and doing the epdb.connect() call on the remote side as Michael’s post suggests in [http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible](http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible)?

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [June 12, 2014, 2:37pm UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448/3 "2014-06-12T14:37:03Z")

</div>

[epdb.st](http://epdb.st)() sets a normal breakpoint which is only going to work if you run it from a python script and not via a module. Modules are executed as a separate process, and you won’t see the [epdb.st](http://epdb.st)() debugger shell. In order to debug a module, you need epdb.serve() and then either epdb.connect() from a python shell per mdehaan’s blog post or simply “telnet localhost 8080”.

---

<div class="post-metadata">

**Author:** ![howachen](https://avatars.discourse-cdn.com/v4/letter/h/54ee81/32.png) [@howachen](https://forum.ansible.com/u/howachen)\
**Post date:** [June 13, 2014, 4:37am UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448/4 "2014-06-13T04:37:30Z")

</div>

Hello, here is my full code listing for the module:

#!/usr/bin/python

import sys

import os

import epdb

import subprocess

def hello(module):

x = 9901

epdb.serve()

def main():

arguments = dict(

id=dict(type=‘str’)

)

module = AnsibleModule(arguments)

params = module.params

hello(module)

module.exit\_json(changed=True)

# this is magic, see lib/ansible/module\_common.py

#\<\<INCLUDE\_ANSIBLE\_MODULE\_COMMON\>\>

main()

# ========

And I execute via # ansible --forks 1 --module-path . localhost -m test -a ‘’

The command was hang-ed, and I cannot see port 8080 is listening.

And my hosts file is:

[localhost]

127.0.0.1 ansible\_connection=local

Any idea?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 14, 2014, 6:38pm UTC](https://forum.ansible.com/t/debugging-ansible-with-epdb/15448/5 "2014-06-14T18:38:59Z")

</div>

After the breakpoint is hit, are you connecting to the listening epdb point with python -c “import epdb; epdb.connect()”
