Reputation:
I have a template in the folder path ~/sample_ansible/roles/carbon/templates/carbon.xml.j2
and I have a file named carbon.xml in the folder path ~/ansible_istio/wso2_apim/wso2am-3.0.0/repository/conf/
. I need to override carbon.xml
file with the template. How to do this task?
My code
- name: Overwrite file
copy:
src: "~/sample_ansible/roles/carbon/templates/carbon.xml.j2"
dest: ~/ansible_istio/wso2_apim/wso2am-3.0.0/repository/conf/
Upvotes: 0
Views: 8367
Reputation: 2568
Did you try this?
- name: Overwrite file
template:
src: "~/sample_ansible/roles/carbon/templates/carbon.xml.j2"
dest: ~/ansible_istio/wso2_apim/wso2am-3.0.0/repository/conf/carbon.xml
Tested:
# cat /tmp/carbon.xml
this is
the initial
contents
# cat /tmp/carbon.xml.j2
This is a new file with {{ansible_hostname}}
Playbook:
- name: Overwrite file
template:
src: /tmp/carbon.xml.j2
dest: /tmp/carbon.xml
changed: [localhost] => { "changed": true, "checksum": "197ece93c57d1a8eaccc6cd9928ede641eef65", "dest": "/tmp/carbon.xml", "diff": [], "gid": 0, "group": "root", ...............
# cat /tmp/carbon.xml
This is a new file with lxxxxx12345
Upvotes: 2