Lee Lee - 1 month ago 37
Bash Question

Replace ansible line using lineinfile

Im working with ansible to change the line for https host

---
- 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 }


It complain that the line is have a problem.
Can anyone help to point it out?

rk2 rk2
Answer

Try using single quotes like this -

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

Also, I see that the attributes dest, state, regexp and line are not indented correctly in the example you mentioned in your question. It should look like this -

---
- 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>'