簡體   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