Find and replace and save at a new destination

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