| 1 |
# test code for the fetch module when using winrm connection |
| 2 |
# (c) 2014, Chris Church <[email protected]> |
| 3 |
|
| 4 |
# This file is part of Ansible |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- name: define host-specific host_output_dir |
| 20 |
set_fact: |
| 21 |
host_output_dir: "{{ output_dir }}/{{ inventory_hostname }}" |
| 22 |
|
| 23 |
- name: clean out the test directory |
| 24 |
file: name={{ host_output_dir|mandatory }} state=absent |
| 25 |
delegate_to: localhost |
| 26 |
run_once: true |
| 27 |
|
| 28 |
- name: create the test directory |
| 29 |
file: name={{ host_output_dir }} state=directory |
| 30 |
delegate_to: localhost |
| 31 |
run_once: true |
| 32 |
|
| 33 |
- name: fetch a small file |
| 34 |
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }} |
| 35 |
register: fetch_small |
| 36 |
|
| 37 |
- name: check fetch small result |
| 38 |
assert: |
| 39 |
that: |
| 40 |
- "fetch_small.changed" |
| 41 |
|
| 42 |
- name: check file created by fetch small |
| 43 |
stat: path={{ fetch_small.dest }} |
| 44 |
delegate_to: localhost |
| 45 |
register: fetch_small_stat |
| 46 |
|
| 47 |
- name: verify fetched small file exists locally |
| 48 |
assert: |
| 49 |
that: |
| 50 |
- "fetch_small_stat.stat.exists" |
| 51 |
- "fetch_small_stat.stat.isreg" |
| 52 |
- "fetch_small_stat.stat.checksum == fetch_small.checksum" |
| 53 |
|
| 54 |
- name: fetch the same small file |
| 55 |
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }} |
| 56 |
register: fetch_small_again |
| 57 |
|
| 58 |
- name: check fetch small result again |
| 59 |
assert: |
| 60 |
that: |
| 61 |
- "not fetch_small_again.changed" |
| 62 |
|
| 63 |
- name: fetch a small file to flat namespace |
| 64 |
fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}/" flat=yes |
| 65 |
register: fetch_flat |
| 66 |
|
| 67 |
- name: check fetch flat result |
| 68 |
assert: |
| 69 |
that: |
| 70 |
- "fetch_flat.changed" |
| 71 |
|
| 72 |
- name: check file created by fetch flat |
| 73 |
stat: path="{{ host_output_dir }}/win.ini" |
| 74 |
delegate_to: localhost |
| 75 |
register: fetch_flat_stat |
| 76 |
|
| 77 |
- name: verify fetched file exists locally in host_output_dir |
| 78 |
assert: |
| 79 |
that: |
| 80 |
- "fetch_flat_stat.stat.exists" |
| 81 |
- "fetch_flat_stat.stat.isreg" |
| 82 |
- "fetch_flat_stat.stat.checksum == fetch_flat.checksum" |
| 83 |
|
| 84 |
#- name: fetch a small file to flat directory (without trailing slash) |
| 85 |
# fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}" flat=yes |
| 86 |
# register: fetch_flat_dir |
| 87 |
|
| 88 |
#- name: check fetch flat to directory result |
| 89 |
# assert: |
| 90 |
# that: |
| 91 |
# - "fetch_flat_dir is not changed" |
| 92 |
|
| 93 |
- name: fetch a large binary file |
| 94 |
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }} |
| 95 |
register: fetch_large |
| 96 |
|
| 97 |
- name: check fetch large binary file result |
| 98 |
assert: |
| 99 |
that: |
| 100 |
- "fetch_large.changed" |
| 101 |
|
| 102 |
- name: check file created by fetch large binary |
| 103 |
stat: path={{ fetch_large.dest }} |
| 104 |
delegate_to: localhost |
| 105 |
register: fetch_large_stat |
| 106 |
|
| 107 |
- name: verify fetched large file exists locally |
| 108 |
assert: |
| 109 |
that: |
| 110 |
- "fetch_large_stat.stat.exists" |
| 111 |
- "fetch_large_stat.stat.isreg" |
| 112 |
- "fetch_large_stat.stat.checksum == fetch_large.checksum" |
| 113 |
|
| 114 |
- name: fetch a large binary file again |
| 115 |
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }} |
| 116 |
register: fetch_large_again |
| 117 |
|
| 118 |
- name: check fetch large binary file result again |
| 119 |
assert: |
| 120 |
that: |
| 121 |
- "not fetch_large_again.changed" |
| 122 |
|
| 123 |
- name: fetch a small file using backslashes in src path |
| 124 |
fetch: src="C:\\Windows\\system.ini" dest={{ host_output_dir }} |
| 125 |
register: fetch_small_bs |
| 126 |
|
| 127 |
- name: check fetch small result with backslashes |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- "fetch_small_bs.changed" |
| 131 |
|
| 132 |
- name: check file created by fetch small with backslashes |
| 133 |
stat: path={{ fetch_small_bs.dest }} |
| 134 |
delegate_to: localhost |
| 135 |
register: fetch_small_bs_stat |
| 136 |
|
| 137 |
- name: verify fetched small file with backslashes exists locally |
| 138 |
assert: |
| 139 |
that: |
| 140 |
- "fetch_small_bs_stat.stat.exists" |
| 141 |
- "fetch_small_bs_stat.stat.isreg" |
| 142 |
- "fetch_small_bs_stat.stat.checksum == fetch_small_bs.checksum" |
| 143 |
|
| 144 |
- name: attempt to fetch a non-existent file - do not fail on missing |
| 145 |
fetch: src="C:/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=no |
| 146 |
register: fetch_missing_nofail |
| 147 |
|
| 148 |
- name: check fetch missing no fail result |
| 149 |
assert: |
| 150 |
that: |
| 151 |
- "fetch_missing_nofail is not failed" |
| 152 |
- "fetch_missing_nofail.msg | length > 0" |
| 153 |
- "fetch_missing_nofail is not changed" |
| 154 |
|
| 155 |
- name: attempt to fetch a non-existent file - fail on missing |
| 156 |
fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=yes |
| 157 |
register: fetch_missing |
| 158 |
ignore_errors: true |
| 159 |
|
| 160 |
- name: check fetch missing with failure |
| 161 |
assert: |
| 162 |
that: |
| 163 |
- "fetch_missing is failed" |
| 164 |
- "fetch_missing.msg | length > 0" |
| 165 |
- "fetch_missing is not changed" |
| 166 |
|
| 167 |
- name: attempt to fetch a non-existent file - fail on missing implicit |
| 168 |
fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }} |
| 169 |
register: fetch_missing_implicit |
| 170 |
ignore_errors: true |
| 171 |
|
| 172 |
- name: check fetch missing with failure on implicit |
| 173 |
assert: |
| 174 |
that: |
| 175 |
- "fetch_missing_implicit is failed" |
| 176 |
- "fetch_missing_implicit.msg | length > 0" |
| 177 |
- "fetch_missing_implicit is not changed" |
| 178 |
|
| 179 |
- name: create empty temp directory |
| 180 |
win_file: |
| 181 |
path: '{{ remote_tmp_dir }}\fetch_tmp' |
| 182 |
state: directory |
| 183 |
|
| 184 |
- name: attempt to fetch a directory |
| 185 |
fetch: src="{{ remote_tmp_dir }}\\fetch_tmp" dest={{ host_output_dir }} |
| 186 |
register: fetch_dir |
| 187 |
ignore_errors: true |
| 188 |
|
| 189 |
- name: check fetch directory result |
| 190 |
assert: |
| 191 |
that: |
| 192 |
# Doesn't fail anymore, only returns a message. |
| 193 |
- "fetch_dir is not changed" |
| 194 |
- "fetch_dir.msg | length > 0" |
| 195 |
|
| 196 |
- name: create file with special characters |
| 197 |
raw: Set-Content -LiteralPath '{{ remote_tmp_dir }}\abc$not var''quote‘‘' -Value 'abc' |
| 198 |
|
| 199 |
- name: fetch file with special characters |
| 200 |
fetch: |
| 201 |
src: '{{ remote_tmp_dir }}\abc$not var''quote‘' |
| 202 |
dest: '{{ host_output_dir }}/' |
| 203 |
flat: yes |
| 204 |
register: fetch_special_file |
| 205 |
|
| 206 |
- name: get content of fetched file |
| 207 |
command: cat {{ (host_output_dir ~ "/abc$not var'quote‘") | quote }} |
| 208 |
register: fetch_special_file_actual |
| 209 |
delegate_to: localhost |
| 210 |
|
| 211 |
- name: assert fetch file with special characters |
| 212 |
assert: |
| 213 |
that: |
| 214 |
- fetch_special_file is changed |
| 215 |
- fetch_special_file.checksum == '34d4150adc3347f1dd8ce19fdf65b74d971ab602' |
| 216 |
- fetch_special_file.dest == host_output_dir + "/abc$not var'quote‘" |
| 217 |
- fetch_special_file_actual.stdout == 'abc' |
| 218 |
|
| 219 |
- name: create file with wildcard characters |
| 220 |
raw: Set-Content -LiteralPath '{{ remote_tmp_dir }}\abc[].txt' -Value 'abc' |
| 221 |
|
| 222 |
- name: fetch file with wildcard characters |
| 223 |
fetch: |
| 224 |
src: '{{ remote_tmp_dir }}\abc[].txt' |
| 225 |
dest: '{{ host_output_dir }}/' |
| 226 |
register: fetch_wildcard_file_nofail |
| 227 |
|
| 228 |
- name: assert fetch file with wildcard characters |
| 229 |
assert: |
| 230 |
that: |
| 231 |
- "fetch_wildcard_file_nofail is not failed" |