community.general/lib/ansible/modules/windows/win_copy.py
Dag Wieers 98934939af win_copy: Add force parameter and check-mode support (#20405)
* win_copy: Add force parameter and check-mode support

The rationale behind this is that if you're working with +3GB files,
creating the checksum takes a lot of time, which we can avoid by simply
testing if the file exists.

I also took the liberty to put the various parameters together. It
probably takes a (neglible) performance hit but makes the code a bit
easier to inspect/work with, as its closer to all other windows modules.

On a normal run, the action plugin does a local checksum of the source
and a remote checksum of the destination. And afterwards, the module
will do another remote checksum of the copied source, a remote checksum
of the original destination, and another remote checksum of the copied
destination.

On a very huge file (think 4GB) that means 5x reading the complete file
(if you have a large cache you may get away with it, otherwise you're
doomed !).

This patch will ensure with `force: no` that not checksums are being
performed.

* Moving presence check before remote checksum

* Adapted to wishes

* Even more performance improvements
2017-02-24 18:10:09 -08:00

102 lines
3.2 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2015, Jon Hawkesworth (@jhawkesworth) <figs@unity.demon.co.uk>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'status': ['stableinterface'],
'supported_by': 'core',
'version': '1.0'}
DOCUMENTATION = r'''
---
module: win_copy
version_added: "1.9.2"
short_description: Copies files to remote locations on windows hosts.
description:
- The C(win_copy) module copies a file on the local box to remote windows locations.
options:
src:
description:
- Local path to a file to copy to the remote server; can be absolute or relative.
If path is a directory, it is copied recursively. In this case, if path ends
with "/", only inside contents of that directory are copied to destination.
Otherwise, if it does not end with "/", the directory itself with all contents
is copied. This behavior is similar to Rsync.
required: true
dest:
description:
- Remote absolute path where the file should be copied to. If src is a directory,
this must be a directory too. Use \\ for path separators.
required: true
force:
version_added: "2.3"
description:
- If set to C(yes), the remote file will be replaced when content is different than the source.
- If set to C(no), the remote file will only be transferred if the destination does not exist.
default: True
choices:
- yes
- no
author: "Jon Hawkesworth (@jhawkesworth)"
'''
EXAMPLES = r'''
- name: Copy a single file
win_copy:
src: /srv/myfiles/foo.conf
dest: C:\Temp\foo.conf
- name: Copy files/temp_files to c:\temp
win_copy:
src: files/temp_files/
dest: C:\Temp\
'''
RETURN = r'''
dest:
description: destination file/path
returned: changed
type: string
sample: C:\Temp\
src:
description: source file used for the copy on the target machine
returned: changed
type: string
sample: /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source
checksum:
description: sha1 checksum of the file after running copy
returned: success
type: string
sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
size:
description: size of the target, after execution
returned: changed (single files only)
type: int
sample: 1220
operation:
description: whether a single file copy took place or a folder copy
returned: changed (single files only)
type: string
sample: file_copy
original_basename:
description: basename of the copied file
returned: changed (single files only)
type: string
sample: foo.txt
'''