blob: 78b6fa02c9b01cde895d29eb006c846608492aa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# test code for the fetch module when using winrm connection
# (c) 2014, Chris Church <chris@ninemoreminutes.com>
# 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/>.
- name: define host-specific host_output_dir
set_fact:
host_output_dir: "{{ output_dir }}/{{ inventory_hostname }}"
- name: clean out the test directory
file: name={{ host_output_dir|mandatory }} state=absent
delegate_to: localhost
run_once: true
- name: create the test directory
file: name={{ host_output_dir }} state=directory
delegate_to: localhost
run_once: true
- name: fetch a small file
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }}
register: fetch_small
- name: check fetch small result
assert:
that:
- "fetch_small.changed"
- name: check file created by fetch small
stat: path={{ fetch_small.dest }}
delegate_to: localhost
register: fetch_small_stat
- name: verify fetched small file exists locally
assert:
that:
- "fetch_small_stat.stat.exists"
- "fetch_small_stat.stat.isreg"
- "fetch_small_stat.stat.checksum == fetch_small.checksum"
- name: fetch the same small file
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }}
register: fetch_small_again
- name: check fetch small result again
assert:
that:
- "not fetch_small_again.changed"
- name: fetch a small file to flat namespace
fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}/" flat=yes
register: fetch_flat
- name: check fetch flat result
assert:
that:
- "fetch_flat.changed"
- name: check file created by fetch flat
stat: path="{{ host_output_dir }}/win.ini"
delegate_to: localhost
register: fetch_flat_stat
- name: verify fetched file exists locally in host_output_dir
assert:
that:
- "fetch_flat_stat.stat.exists"
- "fetch_flat_stat.stat.isreg"
- "fetch_flat_stat.stat.checksum == fetch_flat.checksum"
#- name: fetch a small file to flat directory (without trailing slash)
# fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}" flat=yes
# register: fetch_flat_dir
#- name: check fetch flat to directory result
# assert:
# that:
# - "fetch_flat_dir is not changed"
- name: fetch a large binary file
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }}
register: fetch_large
- name: check fetch large binary file result
assert:
that:
- "fetch_large.changed"
- name: check file created by fetch large binary
stat: path={{ fetch_large.dest }}
delegate_to: localhost
register: fetch_large_stat
- name: verify fetched large file exists locally
assert:
that:
- "fetch_large_stat.stat.exists"
- "fetch_large_stat.stat.isreg"
- "fetch_large_stat.stat.checksum == fetch_large.checksum"
- name: fetch a large binary file again
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }}
register: fetch_large_again
- name: check fetch large binary file result again
assert:
that:
- "not fetch_large_again.changed"
- name: fetch a small file using backslashes in src path
fetch: src="C:\\Windows\\system.ini" dest={{ host_output_dir }}
register: fetch_small_bs
- name: check fetch small result with backslashes
assert:
that:
- "fetch_small_bs.changed"
- name: check file created by fetch small with backslashes
stat: path={{ fetch_small_bs.dest }}
delegate_to: localhost
register: fetch_small_bs_stat
- name: verify fetched small file with backslashes exists locally
assert:
that:
- "fetch_small_bs_stat.stat.exists"
- "fetch_small_bs_stat.stat.isreg"
- "fetch_small_bs_stat.stat.checksum == fetch_small_bs.checksum"
- name: attempt to fetch a non-existent file - do not fail on missing
fetch: src="C:/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=no
register: fetch_missing_nofail
- name: check fetch missing no fail result
assert:
that:
- "fetch_missing_nofail is not failed"
- "fetch_missing_nofail.msg"
- "fetch_missing_nofail is not changed"
- name: attempt to fetch a non-existent file - fail on missing
fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=yes
register: fetch_missing
ignore_errors: true
- name: check fetch missing with failure
assert:
that:
- "fetch_missing is failed"
- "fetch_missing.msg"
- "fetch_missing is not changed"
- name: attempt to fetch a non-existent file - fail on missing implicit
fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }}
register: fetch_missing_implicit
ignore_errors: true
- name: check fetch missing with failure on implicit
assert:
that:
- "fetch_missing_implicit is failed"
- "fetch_missing_implicit.msg"
- "fetch_missing_implicit is not changed"
- name: attempt to fetch a directory
fetch: src="C:\\Windows" dest={{ host_output_dir }}
register: fetch_dir
ignore_errors: true
- name: check fetch directory result
assert:
that:
# Doesn't fail anymore, only returns a message.
- "fetch_dir is not changed"
- "fetch_dir.msg"
- name: create file with special characters
raw: Set-Content -LiteralPath '{{ remote_tmp_dir }}\abc$not var''quote‘‘' -Value 'abc'
- name: fetch file with special characters
fetch:
src: '{{ remote_tmp_dir }}\abc$not var''quote‘'
dest: '{{ host_output_dir }}/'
flat: yes
register: fetch_special_file
- name: get content of fetched file
command: cat {{ (host_output_dir ~ "/abc$not var'quote‘") | quote }}
register: fetch_special_file_actual
delegate_to: localhost
- name: assert fetch file with special characters
assert:
that:
- fetch_special_file is changed
- fetch_special_file.checksum == '34d4150adc3347f1dd8ce19fdf65b74d971ab602'
- fetch_special_file.dest == host_output_dir + "/abc$not var'quote‘"
- fetch_special_file_actual.stdout == 'abc'
|