Ansible Playbook不断向我的文件中添加^M
我有下面的ansible剧本,我在其中识别文件中的一个字符串,并用另一个字符串替换它Ansible Playbook不断向我的文件中添加^M,ansible,character,Ansible,Character,我有下面的ansible剧本,我在其中识别文件中的一个字符串,并用另一个字符串替换它 --- - name: Ansible Playbook hosts: webserver1 remote_user: user45 tasks: - name: Replacing content with other lineinfile: path: /home/user45/run.sh regexp: '^(.*)DEBUG=(.*)$' lin
---
- 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'
上述方法有效,但它会在该文件的每一行和每一空行的末尾添加^M
从我在网上读到的内容来看,这通常发生在从Windows复制并粘贴到Linux时,但我是手动输入的,所以我有点困惑
Playbook正在Linux Redhat 7上运行请验证您的脚本“/home/user45/run.sh”。其中似乎存在回车符。无论出于何种原因,Lineinfle添加^M。。如果我将其更改为使用替换模块,则不会添加^M位
---
- 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'
您在哪个操作系统上运行playbook?playbook在Linux Redhat 7I上运行我怀疑
run.sh
已经有Windows风格的行尾(即它已经有回车^M
字符)。您可以使用od-c/home/user45/run.sh
命令检查这一点<代码>^M字符将显示为\r
。您是对的。。我在输出中看到/r确认,回车符在run.sh中不存在ansible touch之前ansible verison是什么?让我们知道您正在运行的主机服务器和远程服务器(webserver1)操作系统的详细信息。如果可能,请发布详细的输出以进一步挖掘。