# Line breaks are excluded when copying a file from ansible linux host to windows server using win\_copy

**URL:** <https://forum.ansible.com/t/line-breaks-are-excluded-when-copying-a-file-from-ansible-linux-host-to-windows-server-using-win-copy/20760>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [March 3, 2016, 11:33am UTC](https://forum.ansible.com/t/line-breaks-are-excluded-when-copying-a-file-from-ansible-linux-host-to-windows-server-using-win-copy/20760 "2016-03-03T11:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 3, 2016, 11:33am UTC](https://forum.ansible.com/t/line-breaks-are-excluded-when-copying-a-file-from-ansible-linux-host-to-windows-server-using-win-copy/20760/1 "2016-03-03T11:33:17Z")

</div>

I am copying some text files located on a linux file system to windows file system using the win\_copy module of Ansible. The final copied file do not have line breaks in it.

So the file which is like this on linux:

line1  
line2  
line3

Becomes this on windows:  
line1line2line3

How can i make sure win\_copy just copy the file exactly as it is ?

---

<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:** [March 3, 2016, 5:59pm UTC](https://forum.ansible.com/t/line-breaks-are-excluded-when-copying-a-file-from-ansible-linux-host-to-windows-server-using-win-copy/20760/2 "2016-03-03T17:59:32Z")

</div>

My guess is you are hitting the difference between what linux and windows considers a line ending.

linux is happy with \n

windows wants \r\n

if you run

od -cx yourfile

you will probably only see \n

if the file was originally created on a windows machine, in say, Notepad, then it will get the \r\n line endings.

I suggest you do the following:

edit the file in Notepad on a windows machine.  
use the fetch module to copy it from the windows machine to your ansible controller  
use od -cx to check it has windows line endings  
the file from windows should now copy across unmodified when using win\_copy

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Nick\_Mellor](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@Nick\_Mellor](https://forum.ansible.com/u/Nick_Mellor)\
**Post date:** [September 4, 2017, 5:49am UTC](https://forum.ansible.com/t/line-breaks-are-excluded-when-copying-a-file-from-ansible-linux-host-to-windows-server-using-win-copy/20760/3 "2017-09-04T05:49:45Z")

</div>

Hi Ishan,

As mentioned previously, the file has not changed, just that Windows and Linux expect different line endings.

This is what worked for me using Powershell, converting Linux line-endings to Windows line-endings:

- name: convert line endings from Linux to Windows (PowerShell)

win\_shell: ‘(Get-Content “filename\_from”) -replace “`n", "`r`n” | Set-Content “filename\_to.txt”’

The reason I needed to do this was that I was checking out text files on Linux, then copying them to a Windows server.

it automatically ensures files have the “right” line-endings during checkout (meaning “right” for the machine doing the checkout, not the machine the file’s copied to.)

Cheers,

Nick
