Ansible: Is it possible to search replace single word


In the lineinfile module, it replaces the full line.

If the line is long I have to repeat the whole line again.

Let us suppose I want to replace the single word in the file:

this is the playbook:

is there any way to achieve someting like sed 's/horse/dog/g' ?


You can use backreferences to retrieve other parts(that should not be changed) of the line:

Leave a Reply