blob: f23ebf6350031983815702d90b5392ada8895b4b (
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# test code for the copy module and action plugin
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.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: record the output directory
set_fact: output_file={{win_output_dir}}/foo.txt
- name: copy an empty file
win_copy:
src: empty.txt
dest: "{{win_output_dir}}/empty.txt"
register: copy_empty_result
- name: check copy empty result
assert:
that:
- copy_empty_result|changed
- copy_empty_result.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
- name: stat the empty file
win_stat:
path: "{{win_output_dir}}/empty.txt"
register: stat_empty_result
- name: check that empty file really was created
assert:
that:
- stat_empty_result.stat.exists
- stat_empty_result.stat.size == 0
- name: copy an empty file again
win_copy:
src: empty.txt
dest: "{{win_output_dir}}/empty.txt"
register: copy_empty_again_result
- name: check copy empty again result
assert:
that:
- not copy_empty_again_result|changed
- copy_empty_again_result.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
- name: initiate a basic copy
#- name: initiate a basic copy, and also test the mode
# win_copy: src=foo.txt dest={{output_file}} mode=0444
win_copy: src=foo.txt dest={{output_file}}
register: copy_result
- debug: var=copy_result
#- name: check the presence of the output file
- name: check the mode of the output file
win_file: name={{output_file}} state=file
register: file_result_check
- debug: var=file_result_check
#- name: assert the mode is correct
# assert:
# that:
# - "file_result_check.mode == '0444'"
- name: assert basic copy worked
assert:
that:
- "'changed' in copy_result"
# - "'dest' in copy_result"
# - "'group' in copy_result"
# - "'gid' in copy_result"
- "'checksum' in copy_result"
# - "'owner' in copy_result"
# - "'size' in copy_result"
# - "'src' in copy_result"
# - "'state' in copy_result"
# - "'uid' in copy_result"
- name: verify that the file was marked as changed
assert:
that:
- "copy_result.changed == true"
- name: verify that the file checksum is correct
assert:
that:
- "copy_result.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
- name: check the stat results of the file
win_stat: path={{output_file}}
register: stat_results
- debug: var=stat_results
- name: assert the stat results are correct
assert:
that:
- "stat_results.stat.exists == true"
# - "stat_results.stat.isblk == false"
# - "stat_results.stat.isfifo == false"
# - "stat_results.stat.isreg == true"
# - "stat_results.stat.issock == false"
- "stat_results.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
- name: overwrite the file via same means
win_copy: src=foo.txt dest={{output_file}}
register: copy_result2
- name: assert that the file was not changed
assert:
that:
- "not copy_result2|changed"
# content system not available in win_copy right now
#- name: overwrite the file using the content system
# win_copy: content="modified" dest={{output_file}}
# register: copy_result3
#
#- name: assert that the file has changed
# assert:
# that:
# - "copy_result3|changed"
# - "'content' not in copy_result3"
# test recursive copy
- name: set the output subdirectory
set_fact: output_subdir={{win_output_dir}}/sub/
- name: make an output subdirectory
win_file: name={{output_subdir}} state=directory
- name: test recursive copy to directory
# win_copy: src=subdir dest={{output_subdir}} directory_mode=0700
win_copy: src=subdir dest={{output_subdir}}
register: recursive_copy_result
- debug: var=recursive_copy_result
- name: check that a file in a directory was transferred
win_stat: path={{win_output_dir}}/sub/subdir/bar.txt
register: stat_bar
- name: check that a file in a deeper directory was transferred
win_stat: path={{win_output_dir}}/sub/subdir/subdir2/baz.txt
register: stat_bar2
- name: check that a file in a directory whose parent contains a directory alone was transferred
win_stat: path={{win_output_dir}}/sub/subdir/subdir2/subdir3/subdir4/qux.txt
register: stat_bar3
- name: assert recursive copy things
assert:
that:
- "stat_bar.stat.exists"
- "stat_bar2.stat.exists"
- "stat_bar3.stat.exists"
- name: stat the recursively copied directories
win_stat: path={{win_output_dir}}/sub/{{item}}
register: dir_stats
with_items:
- "subdir"
- "subdir/subdir2"
- "subdir/subdir2/subdir3"
- "subdir/subdir2/subdir3/subdir4"
# can't check file mode on windows so commenting this one out.
#- name: assert recursive copied directories mode
# assert:
# that:
# - "{{item.stat.mode}} == 0700"
# with_items: "{{dir_stats.results}}"
# errors on this aren't presently ignored so this test is commented out. But it would be nice to fix.
#
# content param not available in win_copy
#- name: overwrite the file again using the content system, also passing along file params
# win_copy: content="modified" dest={{output_file}}
# register: copy_result4
#- name: assert invalid copy input location fails
# win_copy: src=invalid_file_location_does_not_exist dest={{win_output_dir}}/file.txt
# ignore_errors: True
# register: failed_copy
# owner not available in win_copy, commenting out
#- name: copy already copied directory again
# win_copy: src=subdir dest={{output_subdir | expanduser}} owner={{ansible_ssh_user}}
# register: copy_result5
#- name: assert that the directory was not changed
# assert:
# that:
# - "not copy_result5|changed"
# content not available in win_copy, commenting out.
# issue 8394
#- name: create a file with content and a literal multiline block
# win_copy: |
# content='this is the first line
# this is the second line
#
# this line is after an empty line
# this line is the last line
# '
# dest={{win_output_dir}}/multiline.txt
# register: copy_result6
#- debug: var=copy_result6
#- name: assert the multiline file was created correctly
# assert:
# that:
# - "copy_result6.changed"
# - "copy_result6.dest == '{{win_output_dir|expanduser}}/multiline.txt'"
# - "copy_result6.checksum == '1627d51e7e607c92cf1a502bf0c6cce3'"
# test overwriting a file as an unprivileged user (pull request #8624)
# this can't be relative to {{win_output_dir}} as ~root usually has mode 700
#- name: create world writable directory
#win_file: dest=/tmp/worldwritable state=directory mode=0777
#- name: create world writable file
# win_copy: dest=/tmp/worldwritable/file.txt content="bar" mode=0666
#- name: overwrite the file as user nobody
# win_copy: dest=/tmp/worldwritable/file.txt content="baz"
# become: yes
# become_user: nobody
# register: copy_result7
#- name: assert the file was overwritten
# assert:
# that:
# - "copy_result7.changed"
# - "copy_result7.dest == '/tmp/worldwritable/file.txt'"
# - "copy_result7.checksum == '73feffa4b7f6bb68e44cf984c85f6e88'"
#- name: clean up
# win_file: dest=/tmp/worldwritable state=absent
# test overwritting a link using "follow=yes" so that the link
# is preserved and the link target is updated
#- name: create a test file to symlink to
# win_copy: dest={{win_output_dir}}/follow_test content="this is the follow test file\n"
#
#- name: create a symlink to the test file
# win_file: path={{win_output_dir}}/follow_link src='./follow_test' state=link
#
#- name: update the test file using follow=True to preserve the link
# win_copy: dest={{win_output_dir}}/follow_link content="this is the new content\n" follow=yes
# register: replace_follow_result
#- name: stat the link path
# win_stat: path={{win_output_dir}}/follow_link
# register: stat_link_result
#
#- name: assert that the link is still a link
# assert:
# that:
# - stat_link_result.stat.islnk
#
#- name: get the md5 of the link target
# shell: checksum {{win_output_dir}}/follow_test | cut -f1 -sd ' '
# register: target_file_result
#- name: assert that the link target was updated
# assert:
# that:
# - replace_follow_result.checksum == target_file_result.stdout
- name: clean up sub
win_file: path={{win_output_dir}}/sub state=absent
- name: clean up foo.txt
win_file: path={{win_output_dir}}/foo.txt state=absent
|