# How to get newline characters to be interpreted using debug and hipchat

**URL:** <https://forum.ansible.com/t/how-to-get-newline-characters-to-be-interpreted-using-debug-and-hipchat/17385>\
**Category:** Ansible Project\
**Created:** [January 27, 2015, 7:19pm UTC](https://forum.ansible.com/t/how-to-get-newline-characters-to-be-interpreted-using-debug-and-hipchat/17385 "2015-01-27T19:19:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_Allen](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Kathy\_Allen](https://forum.ansible.com/u/Kathy_Allen)\
**Post date:** [January 27, 2015, 7:19pm UTC](https://forum.ansible.com/t/how-to-get-newline-characters-to-be-interpreted-using-debug-and-hipchat/17385/1 "2015-01-27T19:19:01Z")

</div>

Hello. I’m trying to send output via debug and hipchat which I want to appear as multiple lines. But I’m failing. Can anyone advise? In my test below, I of course want the output to show up like this:

i am a runon sentence  
i go on and on

Here is my test play and the results. I’m using ansible 1.8.2.

$ cat q.yml

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [January 28, 2015, 2:38pm UTC](https://forum.ansible.com/t/how-to-get-newline-characters-to-be-interpreted-using-debug-and-hipchat/17385/2 "2015-01-28T14:38:37Z")

</div>

> TASK: [debug msg={{my\_msg}}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> Tuesday 27 January 2015 19:05:10 +0000 (0:00:00.000) 0:00:00.040 \*\*\*\*\*\*\*  
> ok: [127.0.0.1] =\> {  
> "msg": "A - i am a runon sentence\ni go on and on and on"  
> }

I believe this is being processed by Jinja2, which is ignoring the  
newline.

> TASK: [debug msg="B - i am a runon sentence \n i go on and on and on"] \*\*\*\*\*\*\*\*  
> Tuesday 27 January 2015 19:05:10 +0000 (0:00:00.005) 0:00:00.045 \*\*\*\*\*\*\*  
> ok: [127.0.0.1] =\> {  
> "msg": "B - i am a runon sentence \\n i go on and on and on"  
> }

Here debug is calling exit\_json() which in turns calls json.dumps() [1],  
which will escape the newline.

> > > json.dumps("one line\nanother line")

'"one line\\nanother line"'

You'll notice that in hipchat you don't see "\\n" but "\n". The function  
send\_msg() in the hipchat module is correctly calling urllib.urlencode()  
to create the URL and then making the external call (no JSON involved  
here). I believe this is a separate issue (i.e. hipchat not correctly  
interpreting newlines).

[1] - [https://docs.python.org/2/library/json.html](https://docs.python.org/2/library/json.html)
