Copy Module doesnt override destination file

4,304 views
Skip to first unread message

Anushri Mishra

unread,
Aug 8, 2016, 12:56:44 PM8/8/16
to Ansible Project
hi,

so this is what I have in my yml file:

-   name: Copy War File

    copy: src=externaluserwebapi.war dest=/usr/share/tomcat7/webapps

    become: True

    become_method: sudo


and this is what I get when I run playbook:

ok: [10.1.33.227] => {"changed": false, "checksum": "c93572d33bd0555a87341380ac389382c225a92d", "dest": "/usr/share/tomcat7/webapps/externaluserwebapi.war", "gid": 0, "group": "root", "invocation": {"module_args": {"backup": false, "content": null, "delimiter": null, "dest": "/usr/share/tomcat7/webapps/externaluserwebapi.war", "directory_mode": null, "follow": false, "force": true, "group": null, "mode": null, "original_basename": "externaluserwebapi.war", "owner": null, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": "/home/ec2-user/.ansible/tmp/ansible-tmp-1470673998.42-22221732776252/source", "validate": null}}, "md5sum": "ba5224fb84a5f82d5fa7b8a8f83c4b2e", "mode": "0644", "owner": "root", "size": 17027813, "src": "/home/ec2-user/.ansible/tmp/ansible-tmp-1470673998.42-22221732776252/source", "state": "file", "uid": 0}



Not sure why but copy module is not overriding the script in destination directory.I read that by default it is force=yes.Please help.

Kai Stian Olstad

unread,
Aug 8, 2016, 7:08:41 PM8/8/16
to ansible...@googlegroups.com
The reason is because the files is identical.

To debug you could add this tasks.

Add this two task before "Copy War File"
- stat:
path=externaluserwebapi.war
delegate_to: localhost
register: result

- debug: var=result

and add this two task after "Copy War File"
- stat:
path=/usr/share/tomcat7/webapps
register: result

- debug: var=result

--
Kai Stian Olstad

Anushri Mishra

unread,
Aug 9, 2016, 5:34:10 PM8/9/16
to Ansible Project
Thanks Kai.Yes,the files are identical.But there should be some way to overwrite it.Is there any way?

Kai Stian Olstad

unread,
Aug 9, 2016, 5:56:41 PM8/9/16
to ansible...@googlegroups.com
On 09. aug. 2016 23:34, Anushri Mishra wrote:
> Thanks Kai.Yes,the files are identical.But there should be some way to
> overwrite it.Is there any way?

No, this is part of Ansibles idempontecy[1], it does not do any changes
if the files is identical.
Why do you want to overwrite the file if it's identical, overwrite it
will have no function since nothing will change.


[1] https://docs.ansible.com/ansible/glossary.html#term-idempotency

--
Kai Stian Olstad

Anushri Mishra

unread,
Aug 9, 2016, 6:07:27 PM8/9/16
to Ansible Project
k got it.thx.


On Monday, August 8, 2016 at 12:56:44 PM UTC-4, Anushri Mishra wrote:
Reply all
Reply to author
Forward
0 new messages