Ansible Playbook 不断将 ^M 添加到我的文件中

问题描述 投票:0回答:3

我有下面的 ansible 剧本,我在其中识别文件中的字符串并将其替换为另一个

---
- 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 上运行

ansible character
3个回答
0
投票

请验证您的脚本“/home/user45/run.sh”。看起来那里存在回车符。


0
投票

无论出于何种原因,lineinfile 添加了 ^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'

0
投票

它适用于 ansible 2.9:

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

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

享受;)

© www.soinside.com 2019 - 2024. All rights reserved.