How to debug/log message when writing Ansible Module?

3,895 views
Skip to first unread message

howa...@gmail.com

unread,
Jun 9, 2014, 10:09:22 AM6/9/14
to ansible...@googlegroups.com
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


James Cammarata

unread,
Jun 9, 2014, 10:24:27 AM6/9/14
to ansible...@googlegroups.com
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 received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b9e18a9b-f079-4cac-85c8-fd6bb545c2fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jaime Gago

unread,
Jun 9, 2014, 2:37:45 PM6/9/14
to ansible...@googlegroups.com

howa...@gmail.com

unread,
Jun 10, 2014, 9:15:41 AM6/10/14
to ansible...@googlegroups.com
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()

Michael DeHaan

unread,
Jun 11, 2014, 2:56:47 PM6/11/14
to ansible...@googlegroups.com
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.




Reply all
Reply to author
Forward
0 new messages