繁体   English   中英

使用lineinfile替换ansible行

[英]Replace ansible line using lineinfile

我正在与ansible一起更改https主机的行

---
  - name: "change http to https"
    lineinfile:
    dest: "{{ install_dir }}/xx/abc-out.xml"
    state: present
    regexp: "<column name="PARAM_VALUE">http://host.com:42003</column>"
    line:  "<column name="PARAM_VALUE">https://host.com:42091</column>"

---
- name: Change line
  vars_files:
    - vars/conn.yml
  become_user: "{{ app_user }}"
  become: true
  roles:
      - { role: https-host }

它抱怨线路有问题。 有人可以指出吗?

尝试使用像这样的单引号-

    regexp: '<column name="PARAM_VALUE">http://host.com:42003</column>'
    line:  '<column name="PARAM_VALUE">https://host.com:42091</column>'

另外,在您提到的示例中,我看到属性deststateregexpline没有正确缩进。 它看起来应该像这样-

---
- name: "change http to https"
  lineinfile:
    dest: "{{ install_dir }}/xx/abc-out.xml"
    state: present
    regexp: '<column name="PARAM_VALUE">http://host.com:42003</column>'
    line:  '<column name="PARAM_VALUE">https://host.com:42091</column>'
regexp: '         <column name="PARAM_VALUE">https://host.com:12360</column>'

正如我在评论中提到的。 间距和更改为单引号有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM