TECHIES WORLD

For Techs.... Techniques.... Technologies....

BashLinux

How to replace strings in file using Ansible

We can use the replace module of Ansible to replace strings in a file.

Sample playbook snippet is given below.

  - name: Replace string
    replace:
        path: full-path-to-file
        regexp: "keyword1"
        replace: "keyword2"

Here we need to replace full-path-to-file, keyword1 and keyword2 with required values. Keyword1 is the search keyword and keyword2 is the replacement keyword.

That's all…

Leave a Reply