Find and replace and save at a new destination

8 views
Skip to first unread message

rahul raviz

unread,
Mar 10, 2022, 10:51:09 PM3/10/22
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages