# how to add new line character in copy module to write multiple lines

**URL:** <https://forum.ansible.com/t/how-to-add-new-line-character-in-copy-module-to-write-multiple-lines/26807>\
**Category:** Ansible Project\
**Created:** [February 21, 2018, 6:40am UTC](https://forum.ansible.com/t/how-to-add-new-line-character-in-copy-module-to-write-multiple-lines/26807 "2018-02-21T06:40:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [February 21, 2018, 6:40am UTC](https://forum.ansible.com/t/how-to-add-new-line-character-in-copy-module-to-write-multiple-lines/26807/1 "2018-02-21T06:40:54Z")

</div>

Hi All,

I want to write few lines into a file using copy module by line by line but it’s not happening,

- name: “Storing the data details”  
copy:  
content: ’ IP: xx.xx.xx.xx \n  
IPV4: xx.xx.xx.xx \n  
HOST\_NAME: {{host\_name}} \n  
Network: {{network}} \n’  
dest: “/root/home/network.conf”

Excepted o/p:  
IP: xx.xx.xx.xx  
IPV4: xx.xx.xx.xx  
HOST\_NAME: some\_name  
Network: local

Actual o/p:  
IP:xx.xx.xx.xx \n IPV4: xx.xx.xx.xx \n HOST\_NAME: some\_name \n Network: local \n

how can i achieve this as i want in Excepted one.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [February 21, 2018, 6:50am UTC](https://forum.ansible.com/t/how-to-add-new-line-character-in-copy-module-to-write-multiple-lines/26807/2 "2018-02-21T06:50:12Z")

</div>

Hi,

> I want to write few lines into a file using copy module by line by  
> line but it's not happening,
> 
> - name: "Storing the data details"  
> &nbsp;&nbsp;copy:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: ' IP: xx.xx.xx.xx \n  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPV4: xx.xx.xx.xx \n  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HOST\_NAME: {{host\_name}} \n  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Network: {{network}} \n'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "/root/home/network.conf"
> 
> Excepted o/p:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IP: xx.xx.xx.xx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPV4: xx.xx.xx.xx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HOST\_NAME: some\_name  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Network: local
> 
> Actual o/p:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IP:xx.xx.xx.xx \n IPV4: xx.xx.xx.xx \n HOST\_NAME: some\_name  
> \n Network: local \n
> 
> how can i achieve this as i want in Excepted one.

replace the single quotes by double quotes:

- name: "Storing the data details"  
&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: " IP: xx.xx.xx.xx \n  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPV4: xx.xx.xx.xx \n  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HOST\_NAME: {{host\_name}} \n  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Network: {{network}} \n"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "/root/home/network.conf"

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [February 21, 2018, 6:59am UTC](https://forum.ansible.com/t/how-to-add-new-line-character-in-copy-module-to-write-multiple-lines/26807/3 "2018-02-21T06:59:44Z")

</div>

That worked :)…! thanks Felix
