Ansible: repeated lines exists but update only specific occurrence -


i have change

`<!--<parameter name=\"hostnameverifier\">defaultandlocalhost</parameter>-->` 

to <!--<parameter name=\"hostnameverifier\">allowall</parameter>--> in apim_home/repository/conf/axis2/axis2.xml.

i using

- name: "modify hostnameverifier" lineinfile: dest: "/home/ec2-user/ansible-test/wso2am-2.0.0/repository/conf/axis2/axis2.xml" state: "present" line: "\t\t<parameter name=\"hostnameverifier\">allowall</parameter>" regexp: "<!--<parameter name=\"hostnameverifier\">defaultandlocalhost</parameter>-->"

this replacing 3rd occurrence of regexp. want replace 2nd occurrence. how do that?

you can't lineinfile. docs:

...only last line found replaced...

and lineinfile iterates line-by-line – can't add more context it.

you should use replace module , add more context regexp match exatly part of file want modify. can use multiline patterns here.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -