# Ansible stdout\_lines writes as list syntax \[u'text1',u'text2'\] instead of multiline?

**URL:** <https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342>\
**Category:** Ansible Project\
**Created:** [December 29, 2016, 5:44am UTC](https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342 "2016-12-29T05:44:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![burns498](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@burns498](https://forum.ansible.com/u/burns498)\
**Post date:** [December 29, 2016, 5:44am UTC](https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342/1 "2016-12-29T05:44:54Z")

</div>

Hello - Assistance requested with stdout\_lines output.

I have some tasks that take diff results of two files and then writes the output to a log.

Code Snippet:

`

- name: Gather diff output of deployed changes  
command: “diff {{ deployed\_copy\_output.dest }} {{ deployed\_copy\_output.backup\_file }}”  
register: diff\_output  
failed\_when: diff\_output.rc \> 1

- name: Log diff changes  
blockinfile:  
dest: “{{ log\_dir }}/{{ pb\_diff\_logname }}”  
content: |  
{{ app\_log\_header }}  
Command: ‘diff {{ deployed\_copy\_output.dest }} {{ deployed\_copy\_output.backup\_file }}’  
{{ diff\_output.stdout\_lines }}  
{{ app\_log\_footer }}  
create: yes  
insertafter: EOF  
marker: “{{ app\_log\_marker }}”

`

This results in output that looks like the below.

> * * *
> 
> Command: ‘diff /opt/wmspt/.profile /opt/wmspt/.profile.2016-12-28@23:06:41~’  
> [u’2a3’, u’\> echo hi’]
> 
> * * *

I would expect it to look more like the debug output:

> TASK [role\_config\_shared\_profile : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [ptl01a0fap006] =\> {  
> “diff\_output”: {  
> “changed”: false,  
> “cmd”: [  
> “diff”,  
> “/opt/wmspt/.profile”,  
> “/opt/wmspt/.profile.2016-12-28@23:27:24~”  
> ],  
> “delta”: “0:00:00.111675”,  
> “end”: “2016-12-28 23:27:25.068251”,  
> “failed”: false,  
> “failed\_when\_result”: false,  
> “rc”: 1,  
> “start”: “2016-12-28 23:27:24.956576”,  
> “stderr”: “”,  
> “stdout”: “2a3\n\> echo hi”,  
> “stdout\_lines”: [  
> “2a3”,  
> “\> echo hi”  
> ],  
> “warnings”:   
> }  
> }

Writing the stdout\_lines has some sort of list syntax with [u’text1’,u’text2’], even though debug the same info is correct multiline output. Is there something that I’m missing here?

Thanks

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [December 29, 2016, 7:14am UTC](https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342/2 "2016-12-29T07:14:03Z")

</div>

Try using join, like this

{{ results.stdout\_lines | join ('\n') }}

Not tried, but hope it helps,

Jon

---

<div class="post-metadata">

**Author:** ![burns498](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@burns498](https://forum.ansible.com/u/burns498)\
**Post date:** [December 29, 2016, 4:00pm UTC](https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342/3 "2016-12-29T16:00:23Z")

</div>

Hello Jon - Thanks for the help!

The change you suggested did help clean it up a bit. It changed it from a list output to one line string separated by literal ‘\n’. Something like “2a3\n\> echo hi”. This was a step in the right direction.

I did some more digging around and found an answer using [Jinja2 whitespace control](http://jinja.pocoo.org/docs/dev/templates/#whitespace-control). Uses a for loop to parse the list output via jinja2 filters.  
**Updated Code Snippet:**

`

- name: Log diff changes  
blockinfile:  
dest: “{{ log\_dir }}/{{ pb\_diff\_logname }}”  
content: |  
{{ app\_log\_header }}  
Command: ‘diff {{ deployed\_copy\_output.dest }} {{ deployed\_copy\_output.backup\_file }}’  
{% for item in diff\_output.stdout\_lines %}  
{{ item }}  
{% endfor %}  
{{ app\_log\_footer }}  
create: yes  
insertafter: EOF  
marker: “{{ app\_log\_marker }}”

`

The output is then quite clean in the log file.

> * * *
> 
> Command: ‘diff /opt/wmspt/.profile /opt/wmspt/.profile.2016-12-29@08:57:50~’  
> 2a3
> 
> > echo hi
> 
> * * *

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 5, 2017, 9:21pm UTC](https://forum.ansible.com/t/ansible-stdout-lines-writes-as-list-syntax-utext1-utext2-instead-of-multiline/23342/4 "2017-01-05T21:21:37Z")

</div>

Just use stdout … which is a multiline string, stdout\_lines is a split of this for people to use each line in a list.
