On Mon, 7 Jun 2021 23:20:30 -0700 (PDT)
Vinod P <
vinod...@gmail.com> wrote:
> in /etc directory and replace them with new IP address as follows
> sudo find /etc -type f -exec sed -i -e 's/
10.1.3.51/10.2.3.54/g' {} +
For example, given the file
shell> cat etc/file1
10.1.3.50
10.1.3.51
10.1.3.52
the playbook
shell> cat test-007.yml
- hosts: localhost
gather_facts: false
become: true
tasks:
- find:
path: etc
file_type: file
recurse: true
register: result
- replace:
path: "{{ item }}"
regexp: "10.1.3.51"
replace: "10.2.3.54"
loop: "{{ result.files|
map(attribute='path')|
list }}"
gives
shell> ansible-playbook test-007.yml -CD
PLAY [localhost]
******************************************
TASK [find]
******************************************
ok: [localhost]
TASK [replace]
******************************************
--- before: etc/file1 +++ after: etc/file1
@@ -1,3 +1,3 @@
10.1.3.50
-10.1.3.51
+10.2.3.54
10.1.3.52
changed: [localhost] => (item=etc/file1)
--
Vladimir Botka