lineinfile inserts dos style new line character

I’m setting up tomcat, and change a parameter in a config file as follows:

  • name: set max-request-size

lineinfile: dest={{ tomcat_home }}/webapps/manager/WEB-INF/web.xml regexp=“max-request-size” line=“1000000000”

Post processing, lines in the target file web.xml now end with a ^M. The lines that were replaced are fine, e.g.

^M
1000000000 <— OK!
0^M

This is as seen vi, on a RHEL64 system.

What am I doing wrong?

The lineinfile module uses the os.linesep variable to insert newlines, so this should not be happening unless the file had either been edited on a Windows system or had the ^M’s before the edit occurred. Can you verify the original file did not have the incorrect newlines, and that you are not running the playbook from a Windows machine (ie. via cygwin)?