How to debug/log message when writing Ansible Module?

According to this: http://docs.ansible.com/developing_modules.html, it said…

You should also never do this in a module:

print "some status message"

So, how to debug or log message during the development of Ansible module?

Thanks

This is more of a topic for ansible-devel, but to answer your question you can use the hacking/test-module script to run your module. At that point, you can either use print statements or epdb to debug your code, since it’s running locally. If you only want to test your module remotely (ie. a normal ansible run), you can always use the built-in syslog functionatliy.

Normally you should not use print statements because it breaks the JSON output.

You might also want to read this post

http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible

J.

Hey

I’ve tried the information in this link: http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible

But cannot get Ansible to show the interactive shell for debugging, any idea?

ansible --forks 1 --module-path . localhost -m test -a ‘’

Where the test module contains code like…

import epdb
# ...
def some_function():
    x = some_random_object.something_interesting()
    epdb.st()

What happens in your case with the above?

You may possibly be not picking up the ansible out of yoru source tree.

Better question for ansible-devel regardless.