Hello,
I continue my post at 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?
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 ?
tannerjc
(James Tanner)
June 12, 2014, 2:37pm
3
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 () 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”.
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?
After the breakpoint is hit, are you connecting to the listening epdb point with python -c “import epdb; epdb.connect()”