Ansible Playbook keeps adding ^M to my files

邮差的信 提交于 2019-12-11 15:06:31

问题


I have the below ansible playbook where i am identifying a string in a file and replacing it with another

---
- name: Ansible Playbook
  hosts: webserver1
  remote_user: user45

  tasks:
  - name: Replacing content with other
    lineinfile:
     path: /home/user45/run.sh
     regexp: '^(.*)DEBUG=(.*)$'
     line: 'DEBUG=ON'

the above works, but it adds ^M to the end of every other line in that file and every blank line

From what I have read online this normally occurs when you copy and paste from Windows to Linux but i typed this out manually so i am kind of stumped

Playbook is running on Linux Redhat 7


回答1:


Please verify your script "/home/user45/run.sh".Looks like carriage-return character exist in there.




回答2:


For whatever reason lineinfile was adding the ^M .. If I change it to use replace module it does not add the ^M bits

---
- name: Ansible Playbook
  hosts: webserver1
  remote_user: user45

  tasks:
  - name: Replacing content with other
    replace:
     dest: /home/user45/run.sh
     regexp: 'DEBUG=.*'
     line: 'DEBUG=ON'


来源:https://stackoverflow.com/questions/51365284/ansible-playbook-keeps-adding-m-to-my-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!