# Line in file

**URL:** <https://forum.ansible.com/t/line-in-file/32907>\
**Category:** Ansible Project\
**Created:** [May 11, 2020, 12:17pm UTC](https://forum.ansible.com/t/line-in-file/32907 "2020-05-11T12:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [May 11, 2020, 12:17pm UTC](https://forum.ansible.com/t/line-in-file/32907/1 "2020-05-11T12:17:28Z")

</div>

Hi All,

I am using Line in file nodule to write a list output in ansible to a file in the target machine.

Below is the code i have used.

hosts: localhost  
tasks:  
&nbsp;&nbsp;- lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: "NONEXISTENTLINE"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /projects/testing/check.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line : "{{item}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- "{{something}}"

And that something is a list and its value is given below,

["WOAprofile1",  
"WOAprofile2",  
"WOAprofile3"]

When I am using the above line in file prints each value of the list in separate line.  
But I need the output in the file as below,  
WOAprofile1, WOAprofile2, WOAprofile3

Note: the number of lines in the variable "something" will be differ from server to server.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 11, 2020, 12:31pm UTC](https://forum.ansible.com/t/line-in-file/32907/2 "2020-05-11T12:31:36Z")

</div>

Change the line module parameter as below and drop the loop (with\_items)

line: "{{ something | join(', ') }}

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [May 11, 2020, 12:54pm UTC](https://forum.ansible.com/t/line-in-file/32907/3 "2020-05-11T12:54:20Z")

</div>

Thank you for your assistance.
