How to find and replace text/IP address with Ansible

 
- name: Replace text in file
replace:
path: /path/to/file
regexp: 'old_text'
replace: 'new_text'

- name: Replace IP address in file
replace:
path: /path/to/file
regexp: 'old_ip'
replace: 'new_ip'

In this example, the first task replaces the text “old_text” with “new_text” in the file located at “/path/to/file”. The second task replaces the IP address “old_ip” with “new_ip”. The replace module uses regular expressions to match the text to be replaced.

Leave a Comment