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
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