2014-06-18 23:10:10 +02:00
|
|
|
|
# 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/>.
|
|
|
|
|
|
2017-09-16 09:27:18 +02:00
|
|
|
|
- name: define host-specific host_output_dir
|
2016-11-30 06:21:53 +01:00
|
|
|
|
set_fact:
|
2017-09-16 09:27:18 +02:00
|
|
|
|
host_output_dir: "{{ output_dir }}/{{ inventory_hostname }}"
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
2014-06-18 23:10:10 +02:00
|
|
|
|
- name: clean out the test directory
|
2019-04-27 02:33:59 +02:00
|
|
|
|
file: name={{ host_output_dir|mandatory }} state=absent
|
|
|
|
|
delegate_to: localhost
|
2014-12-02 04:18:35 +01:00
|
|
|
|
run_once: true
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: create the test directory
|
2019-04-27 02:33:59 +02:00
|
|
|
|
file: name={{ host_output_dir }} state=directory
|
|
|
|
|
delegate_to: localhost
|
2014-12-02 04:18:35 +01:00
|
|
|
|
run_once: true
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: fetch a small file
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_small
|
|
|
|
|
|
|
|
|
|
- name: check fetch small result
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_small.changed"
|
|
|
|
|
|
|
|
|
|
- name: check file created by fetch small
|
2019-04-27 02:33:59 +02:00
|
|
|
|
stat: path={{ fetch_small.dest }}
|
|
|
|
|
delegate_to: localhost
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_small_stat
|
|
|
|
|
|
|
|
|
|
- name: verify fetched small file exists locally
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_small_stat.stat.exists"
|
|
|
|
|
- "fetch_small_stat.stat.isreg"
|
2017-12-06 00:21:34 +01:00
|
|
|
|
- "fetch_small_stat.stat.checksum == fetch_small.checksum"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: fetch the same small file
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:/Windows/win.ini" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
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
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}/" flat=yes
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_flat
|
|
|
|
|
|
|
|
|
|
- name: check fetch flat result
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_flat.changed"
|
|
|
|
|
|
|
|
|
|
- name: check file created by fetch flat
|
2019-04-27 02:33:59 +02:00
|
|
|
|
stat: path="{{ host_output_dir }}/win.ini"
|
|
|
|
|
delegate_to: localhost
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_flat_stat
|
|
|
|
|
|
2017-09-16 09:27:18 +02:00
|
|
|
|
- name: verify fetched file exists locally in host_output_dir
|
2014-06-18 23:10:10 +02:00
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_flat_stat.stat.exists"
|
|
|
|
|
- "fetch_flat_stat.stat.isreg"
|
2017-12-06 00:21:34 +01:00
|
|
|
|
- "fetch_flat_stat.stat.checksum == fetch_flat.checksum"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
2015-07-24 18:39:54 +02:00
|
|
|
|
#- name: fetch a small file to flat directory (without trailing slash)
|
2017-09-16 09:27:18 +02:00
|
|
|
|
# fetch: src="C:/Windows/win.ini" dest="{{ host_output_dir }}" flat=yes
|
2015-07-24 18:39:54 +02:00
|
|
|
|
# register: fetch_flat_dir
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
2015-07-24 18:39:54 +02:00
|
|
|
|
#- name: check fetch flat to directory result
|
|
|
|
|
# assert:
|
|
|
|
|
# that:
|
2017-11-27 23:58:08 +01:00
|
|
|
|
# - "fetch_flat_dir is not changed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: fetch a large binary file
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_large
|
|
|
|
|
|
|
|
|
|
- name: check fetch large binary file result
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_large.changed"
|
|
|
|
|
|
|
|
|
|
- name: check file created by fetch large binary
|
2019-04-27 02:33:59 +02:00
|
|
|
|
stat: path={{ fetch_large.dest }}
|
|
|
|
|
delegate_to: localhost
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_large_stat
|
|
|
|
|
|
|
|
|
|
- name: verify fetched large file exists locally
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- "fetch_large_stat.stat.exists"
|
|
|
|
|
- "fetch_large_stat.stat.isreg"
|
2017-12-06 00:21:34 +01:00
|
|
|
|
- "fetch_large_stat.stat.checksum == fetch_large.checksum"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: fetch a large binary file again
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:/Windows/explorer.exe" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
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
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:\\Windows\\system.ini" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
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
|
2019-04-27 02:33:59 +02:00
|
|
|
|
stat: path={{ fetch_small_bs.dest }}
|
|
|
|
|
delegate_to: localhost
|
2014-06-18 23:10:10 +02:00
|
|
|
|
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"
|
2017-12-06 00:21:34 +01:00
|
|
|
|
- "fetch_small_bs_stat.stat.checksum == fetch_small_bs.checksum"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: attempt to fetch a non-existent file - do not fail on missing
|
2018-02-21 09:10:23 +01:00
|
|
|
|
fetch: src="C:/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=no
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_missing_nofail
|
|
|
|
|
|
|
|
|
|
- name: check fetch missing no fail result
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
|
- "fetch_missing_nofail is not failed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
- "fetch_missing_nofail.msg"
|
2017-11-27 23:58:08 +01:00
|
|
|
|
- "fetch_missing_nofail is not changed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
|
|
|
|
- name: attempt to fetch a non-existent file - fail on missing
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=yes
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_missing
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: check fetch missing with failure
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
|
- "fetch_missing is failed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
- "fetch_missing.msg"
|
2017-11-27 23:58:08 +01:00
|
|
|
|
- "fetch_missing is not changed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
|
2018-02-21 09:10:23 +01:00
|
|
|
|
- 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"
|
|
|
|
|
|
2014-06-18 23:10:10 +02:00
|
|
|
|
- name: attempt to fetch a directory
|
2017-09-16 09:27:18 +02:00
|
|
|
|
fetch: src="C:\\Windows" dest={{ host_output_dir }}
|
2014-06-18 23:10:10 +02:00
|
|
|
|
register: fetch_dir
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: check fetch directory result
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
2014-12-02 04:18:35 +01:00
|
|
|
|
# Doesn't fail anymore, only returns a message.
|
2017-11-27 23:58:08 +01:00
|
|
|
|
- "fetch_dir is not changed"
|
2014-06-18 23:10:10 +02:00
|
|
|
|
- "fetch_dir.msg"
|
2020-08-25 23:06:51 +02:00
|
|
|
|
|
|
|
|
|
- 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'
|