mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
win_copy: rewrite with new tests and functionality (#27678)
* win_copy rewrite with new tests and functionality * minor pep fixes * Handle UTF-8 filenames in zip * fix for template * when zip assemblies are not available in .net revert to old behaviour of copying one by one * typo fix * some more typos * updated logic to correctly handle when new directories can be created * removed testing file as it is not needed * updated documentation based on PR
This commit is contained in:
parent
688823014f
commit
8e40ac54dd
8 changed files with 1694 additions and 721 deletions
|
@ -1,22 +1,11 @@
|
|||
#!/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/>.
|
||||
|
||||
# (c) 2015, Jon Hawkesworth (@jhawkesworth) <figs@unity.demon.co.uk>
|
||||
# Copyright (c) 2017 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
|
@ -27,8 +16,8 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: win_copy
|
||||
version_added: "1.9.2"
|
||||
short_description: Copies files to remote locations on windows hosts.
|
||||
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.
|
||||
- For non-Windows targets, use the M(copy) module instead.
|
||||
|
@ -44,59 +33,97 @@ options:
|
|||
- 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 or \\ when in "double quotes".
|
||||
- If C(dest) ends with \ then source or the contents of source will be
|
||||
copied to the directory without renaming.
|
||||
- If C(dest) is a nonexistent path, it will only be created if C(dest) ends
|
||||
with "/" or "\", or C(src) is a directory.
|
||||
- If C(src) and C(dest) are files and if the parent directory of C(dest)
|
||||
doesn't exist, then the task will fail.
|
||||
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
|
||||
- If set to C(yes), the file will only be transferred if the content
|
||||
is different than destination.
|
||||
- If set to C(no), the file will only be transferred if the
|
||||
destination does not exist.
|
||||
default: True
|
||||
choices:
|
||||
- yes
|
||||
- no
|
||||
- If set to C(no), no checksuming of the content is performed which can
|
||||
help improve performance on larger files.
|
||||
default: 'yes'
|
||||
type: bool
|
||||
local_follow:
|
||||
version_added: '2.4'
|
||||
description:
|
||||
- This flag indicates that filesystem links in the source tree, if they
|
||||
exist, should be followed.
|
||||
default: 'yes'
|
||||
type: bool
|
||||
remote_src:
|
||||
description:
|
||||
- If False, it will search for src at originating/master machine, if True
|
||||
it will go to the remote/target machine for the src.
|
||||
default: False
|
||||
choices:
|
||||
- True
|
||||
- False
|
||||
default: 'no'
|
||||
type: bool
|
||||
version_added: "2.3"
|
||||
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.
|
||||
relative.
|
||||
- If path is a directory, it is copied (including the source folder name)
|
||||
recursively to C(dest).
|
||||
- If path is a directory and ends with "/", only the inside contents of
|
||||
that directory are copied to the destination. Otherwise, if it does not
|
||||
end with "/", the directory itself with all contents is copied.
|
||||
- If path is a file and dest ends with "\", the file is copied to the
|
||||
folder with the same filename.
|
||||
required: true
|
||||
notes:
|
||||
- For non-Windows targets, use the M(copy) module instead.
|
||||
author: "Jon Hawkesworth (@jhawkesworth)"
|
||||
- Currently win_copy does not support copying symbolic links from both local to
|
||||
remote and remote to remote.
|
||||
- It is recommended that backslashes C(\) are used instead of C(/) when dealing
|
||||
with remote paths.
|
||||
- Because win_copy runs over WinRM, it is not a very efficient transfer
|
||||
mechanism. If sending large files consider hosting them on a web service and
|
||||
using M(win_get_url) instead.
|
||||
author:
|
||||
- Jon Hawkesworth (@jhawkesworth)
|
||||
- Jordan Borean (@jborean93)
|
||||
'''
|
||||
|
||||
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
|
||||
dest: c:\Temp\renamed-foo.conf
|
||||
|
||||
- name: Copy a single file keeping the filename
|
||||
win_copy:
|
||||
src: /src/myfiles/foo.conf
|
||||
dest: c:\temp\
|
||||
|
||||
- name: Copy folder to c:\temp (results in C:\Temp\temp_files)
|
||||
win_copy:
|
||||
src: files/temp_files
|
||||
dest: c:\Temp
|
||||
|
||||
- name: Copy folder contents recursively
|
||||
win_copy:
|
||||
src: files/temp_files/
|
||||
dest: c:\Temp
|
||||
|
||||
- name: Copy a single file where the source is on the remote host
|
||||
win_copy:
|
||||
src: C:\temp\foo.txt
|
||||
dest: C:\ansible\foo.txt
|
||||
remote_src: True
|
||||
|
||||
- name: Copy a folder recursively where the source is on the remote host
|
||||
win_copy:
|
||||
src: C:\temp
|
||||
dest: C:\ansible
|
||||
remote_src: True
|
||||
|
||||
- name: Set the contents of a file
|
||||
win_copy:
|
||||
dest: C:\temp\foo.txt
|
||||
|
@ -121,12 +148,12 @@ checksum:
|
|||
sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
|
||||
size:
|
||||
description: size of the target, after execution
|
||||
returned: changed (src is a file or remote_src == True)
|
||||
returned: changed, src is a file
|
||||
type: int
|
||||
sample: 1220
|
||||
operation:
|
||||
description: whether a single file copy took place or a folder copy
|
||||
returned: changed
|
||||
returned: success
|
||||
type: string
|
||||
sample: file_copy
|
||||
original_basename:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue