# How to debug/log message when writing Ansible Module?

**URL:** <https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429>\
**Category:** Ansible Project\
**Created:** [June 9, 2014, 2:09pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429 "2014-06-09T14:09:22Z")\
**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 9, 2014, 2:09pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429/1 "2014-06-09T14:09:22Z")

</div>

According to this: [http://docs.ansible.com/developing\_modules.html](http://docs.ansible.com/developing_modules.html), it said…

You should also never do this in a module:

```auto
print "some status message"

```

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

Thanks

---

<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 9, 2014, 2:24pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429/2 "2014-06-09T14:24:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jaime\_Gago](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jaime\_Gago](https://forum.ansible.com/u/Jaime_Gago)\
**Post date:** [June 9, 2014, 6:37pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429/3 "2014-06-09T18:37:45Z")

</div>

You might also want to read this post

[http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible](http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible)

J.

---

<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 10, 2014, 1:15pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429/4 "2014-06-10T13:15:41Z")

</div>

Hey

I’ve tried the information in this link: [http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible](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..

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

```

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 11, 2014, 6:56pm UTC](https://forum.ansible.com/t/how-to-debug-log-message-when-writing-ansible-module/15429/5 "2014-06-11T18:56:45Z")

</div>

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.
