| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2015, Jon Hawkesworth (@jhawkesworth) <[email protected]> |
| 5 |
# Copyright: (c) 2017, Ansible Project |
| 6 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 9 |
'status': ['stableinterface'], |
| 10 |
'supported_by': 'core'} |
| 11 |
|
| 12 |
DOCUMENTATION = r""" |
| 13 |
--- |
| 14 |
module: win_copy |
| 15 |
version_added: '1.9.2' |
| 16 |
short_description: Copies files to remote locations on windows hosts |
| 17 |
description: |
| 18 |
- The C(win_copy) module copies a file on the local box to remote windows locations. |
| 19 |
- For non-Windows targets, use the M(copy) module instead. |
| 20 |
options: |
| 21 |
content: |
| 22 |
description: |
| 23 |
- When used instead of C(src), sets the contents of a file directly to the |
| 24 |
specified value. |
| 25 |
- This is for simple values, for anything complex or with formatting please |
| 26 |
switch to the M(template) module. |
| 27 |
type: str |
| 28 |
version_added: '2.3' |
| 29 |
decrypt: |
| 30 |
description: |
| 31 |
- This option controls the autodecryption of source files using vault. |
| 32 |
type: bool |
| 33 |
default: yes |
| 34 |
version_added: '2.5' |
| 35 |
dest: |
| 36 |
description: |
| 37 |
- Remote absolute path where the file should be copied to. |
| 38 |
- If C(src) is a directory, this must be a directory too. |
| 39 |
- Use \ for path separators or \\ when in "double quotes". |
| 40 |
- If C(dest) ends with \ then source or the contents of source will be |
| 41 |
copied to the directory without renaming. |
| 42 |
- If C(dest) is a nonexistent path, it will only be created if C(dest) ends |
| 43 |
with "/" or "\", or C(src) is a directory. |
| 44 |
- If C(src) and C(dest) are files and if the parent directory of C(dest) |
| 45 |
doesn't exist, then the task will fail. |
| 46 |
type: path |
| 47 |
required: yes |
| 48 |
backup: |
| 49 |
description: |
| 50 |
- Determine whether a backup should be created. |
| 51 |
- When set to C(yes), create a backup file including the timestamp information |
| 52 |
so you can get the original file back if you somehow clobbered it incorrectly. |
| 53 |
- No backup is taken when C(remote_src=False) and multiple files are being |
| 54 |
copied. |
| 55 |
type: bool |
| 56 |
default: no |
| 57 |
version_added: '2.8' |
| 58 |
force: |
| 59 |
description: |
| 60 |
- If set to C(yes), the file will only be transferred if the content |
| 61 |
is different than destination. |
| 62 |
- If set to C(no), the file will only be transferred if the |
| 63 |
destination does not exist. |
| 64 |
- If set to C(no), no checksumming of the content is performed which can |
| 65 |
help improve performance on larger files. |
| 66 |
type: bool |
| 67 |
default: yes |
| 68 |
version_added: '2.3' |
| 69 |
local_follow: |
| 70 |
description: |
| 71 |
- This flag indicates that filesystem links in the source tree, if they |
| 72 |
exist, should be followed. |
| 73 |
type: bool |
| 74 |
default: yes |
| 75 |
version_added: '2.4' |
| 76 |
remote_src: |
| 77 |
description: |
| 78 |
- If C(no), it will search for src at originating/master machine. |
| 79 |
- If C(yes), it will go to the remote/target machine for the src. |
| 80 |
type: bool |
| 81 |
default: no |
| 82 |
version_added: '2.3' |
| 83 |
src: |
| 84 |
description: |
| 85 |
- Local path to a file to copy to the remote server; can be absolute or |
| 86 |
relative. |
| 87 |
- If path is a directory, it is copied (including the source folder name) |
| 88 |
recursively to C(dest). |
| 89 |
- If path is a directory and ends with "/", only the inside contents of |
| 90 |
that directory are copied to the destination. Otherwise, if it does not |
| 91 |
end with "/", the directory itself with all contents is copied. |
| 92 |
- If path is a file and dest ends with "\", the file is copied to the |
| 93 |
folder with the same filename. |
| 94 |
- Required unless using C(content). |
| 95 |
type: path |
| 96 |
notes: |
| 97 |
- Currently win_copy does not support copying symbolic links from both local to |
| 98 |
remote and remote to remote. |
| 99 |
- It is recommended that backslashes C(\) are used instead of C(/) when dealing |
| 100 |
with remote paths. |
| 101 |
- Because win_copy runs over WinRM, it is not a very efficient transfer |
| 102 |
mechanism. If sending large files consider hosting them on a web service and |
| 103 |
using M(win_get_url) instead. |
| 104 |
seealso: |
| 105 |
- module: assemble |
| 106 |
- module: copy |
| 107 |
- module: win_get_url |
| 108 |
- module: win_robocopy |
| 109 |
author: |
| 110 |
- Jon Hawkesworth (@jhawkesworth) |
| 111 |
- Jordan Borean (@jborean93) |
| 112 |
""" |
| 113 |
|
| 114 |
EXAMPLES = r""" |
| 115 |
- name: Copy a single file |
| 116 |
win_copy: |
| 117 |
src: /srv/myfiles/foo.conf |
| 118 |
dest: C:\Temp\renamed-foo.conf |
| 119 |
|
| 120 |
- name: Copy a single file, but keep a backup |
| 121 |
win_copy: |
| 122 |
src: /srv/myfiles/foo.conf |
| 123 |
dest: C:\Temp\renamed-foo.conf |
| 124 |
backup: yes |
| 125 |
|
| 126 |
- name: Copy a single file keeping the filename |
| 127 |
win_copy: |
| 128 |
src: /src/myfiles/foo.conf |
| 129 |
dest: C:\Temp\ |
| 130 |
|
| 131 |
- name: Copy folder to C:\Temp (results in C:\Temp\temp_files) |
| 132 |
win_copy: |
| 133 |
src: files/temp_files |
| 134 |
dest: C:\Temp |
| 135 |
|
| 136 |
- name: Copy folder contents recursively |
| 137 |
win_copy: |
| 138 |
src: files/temp_files/ |
| 139 |
dest: C:\Temp |
| 140 |
|
| 141 |
- name: Copy a single file where the source is on the remote host |
| 142 |
win_copy: |
| 143 |
src: C:\Temp\foo.txt |
| 144 |
dest: C:\ansible\foo.txt |
| 145 |
remote_src: yes |
| 146 |
|
| 147 |
- name: Copy a folder recursively where the source is on the remote host |
| 148 |
win_copy: |
| 149 |
src: C:\Temp |
| 150 |
dest: C:\ansible |
| 151 |
remote_src: yes |
| 152 |
|
| 153 |
- name: Set the contents of a file |
| 154 |
win_copy: |
| 155 |
content: abc123 |
| 156 |
dest: C:\Temp\foo.txt |
| 157 |
|
| 158 |
- name: Copy a single file as another user |
| 159 |
win_copy: |
| 160 |
src: NuGet.config |
| 161 |
dest: '%AppData%\NuGet\NuGet.config' |
| 162 |
vars: |
| 163 |
ansible_become_user: user |
| 164 |
ansible_become_password: pass |
| 165 |
# The tmp dir must be set when using win_copy as another user |
| 166 |
# This ensures the become user will have permissions for the operation |
| 167 |
# Make sure to specify a folder both the ansible_user and the become_user have access to (i.e not %TEMP% which is user specific and requires Admin) |
| 168 |
ansible_remote_tmp: 'c:\tmp' |
| 169 |
""" |
| 170 |
|
| 171 |
RETURN = r""" |
| 172 |
backup_file: |
| 173 |
description: Name of the backup file that was created. |
| 174 |
returned: if backup=yes |
| 175 |
type: str |
| 176 |
sample: C:\Path\To\File.txt.11540.20150212-220915.bak |
| 177 |
dest: |
| 178 |
description: Destination file/path. |
| 179 |
returned: changed |
| 180 |
type: str |
| 181 |
sample: C:\Temp\ |
| 182 |
src: |
| 183 |
description: Source file used for the copy on the target machine. |
| 184 |
returned: changed |
| 185 |
type: str |
| 186 |
sample: /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source |
| 187 |
checksum: |
| 188 |
description: SHA1 checksum of the file after running copy. |
| 189 |
returned: success, src is a file |
| 190 |
type: str |
| 191 |
sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827 |
| 192 |
size: |
| 193 |
description: Size of the target, after execution. |
| 194 |
returned: changed, src is a file |
| 195 |
type: int |
| 196 |
sample: 1220 |
| 197 |
operation: |
| 198 |
description: Whether a single file copy took place or a folder copy. |
| 199 |
returned: success |
| 200 |
type: str |
| 201 |
sample: file_copy |
| 202 |
original_basename: |
| 203 |
description: Basename of the copied file. |
| 204 |
returned: changed, src is a file |
| 205 |
type: str |
| 206 |
sample: foo.txt |
| 207 |
""" |