# Find and replace and save at a new destination

**URL:** <https://forum.ansible.com/t/find-and-replace-and-save-at-a-new-destination/36423>\
**Category:** Ansible Project\
**Created:** [March 11, 2022, 3:51am UTC](https://forum.ansible.com/t/find-and-replace-and-save-at-a-new-destination/36423 "2022-03-11T03:51:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul\_raviz](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rahul\_raviz](https://forum.ansible.com/u/rahul_raviz)\
**Post date:** [March 11, 2022, 3:51am UTC](https://forum.ansible.com/t/find-and-replace-and-save-at-a-new-destination/36423/1 "2022-03-11T03:51:09Z")

</div>

Hi,

I am looking for a task to find and replace a couple of items from a template and save it at a new destination. I am not sure how to achieve that. This is what I tried and it will only replace the contents of the template and save the same file, which is not serving the purpose. How can I do this?

- name: Prepare common\_vars.sh  
replace:  
path: “templates/common\_vars.sh”  
regexp: “{{ item.regexp1 }}”  
replace: “{{ item.replace }}”  
with\_items:
- { regexp1: ‘XX’, replace: ‘{{ cust }}’}
- { regexp1: ‘xx’, replace: ‘{{ low\_cust }}’}

delegate\_to: localhost
