Vinod_P
(Vinod P)
1
Hello All,
Need some help with yaml file
I am trying to run find command to fetch old IP address from multiple files 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’ {} +
I can accomplish this using the command but how do I do it using yaml file as i need to run it on multiple servers.
Please help and thanks in advance.
vbotka
(Vladimir Botka)
2
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
cat etc/file1
10.1.3.50
10.1.3.51
10.1.3.52
the playbook
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
ansible-playbook test-007.yml -CD
PLAY [localhost]