mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
win_copy: rewrite with new tests and functionality (#27678)
* win_copy rewrite with new tests and functionality * minor pep fixes * Handle UTF-8 filenames in zip * fix for template * when zip assemblies are not available in .net revert to old behaviour of copying one by one * typo fix * some more typos * updated logic to correctly handle when new directories can be created * removed testing file as it is not needed * updated documentation based on PR
This commit is contained in:
parent
688823014f
commit
8e40ac54dd
8 changed files with 1694 additions and 721 deletions
|
@ -1,563 +1,24 @@
|
|||
# test code for the copy module and action plugin
|
||||
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
---
|
||||
- name: create empty folder
|
||||
file:
|
||||
path: '{{role_path}}/files/subdir/empty'
|
||||
state: directory
|
||||
delegate_to: localhost
|
||||
|
||||
# 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: remove win_output_dir
|
||||
win_file:
|
||||
path: "{{win_output_dir}}"
|
||||
state: absent
|
||||
|
||||
- name: recreate win_output_dir
|
||||
win_file:
|
||||
path: "{{win_output_dir}}"
|
||||
- name: create test folder
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}'
|
||||
state: directory
|
||||
|
||||
- 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
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
register: copy_result
|
||||
|
||||
- name: check that the basic copy of the file was created
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\foo.txt"
|
||||
register: copy_result_stat
|
||||
|
||||
- name: check basic copy result
|
||||
assert:
|
||||
that:
|
||||
- copy_result|changed
|
||||
- copy_result.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_result_stat.stat.exists == True
|
||||
|
||||
- name: initiate a basic copy again
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
register: copy_result_again
|
||||
|
||||
- name: check basic copy result again
|
||||
assert:
|
||||
that:
|
||||
- not copy_result_again|changed
|
||||
- copy_result_again.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy file that exists on remote but checksum different and force is False
|
||||
win_copy:
|
||||
src: empty.txt
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
force: False
|
||||
register: copy_result_no_force_different
|
||||
|
||||
- name: get stat on remote file for assertion
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\foo.txt"
|
||||
register: copy_result_no_force_different_stat
|
||||
|
||||
- name: check that nothing changed when not forcing file and dest exists
|
||||
assert:
|
||||
that:
|
||||
- not copy_result_no_force_different|changed
|
||||
- copy_result_no_force_different_stat.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy file that doesn't exist on remote and force is False
|
||||
win_copy:
|
||||
src: empty.txt
|
||||
dest: "{{win_output_dir}}\\no_force.txt"
|
||||
force: False
|
||||
register: copy_result_no_force
|
||||
|
||||
- name: get stat on remote file for assertion
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\no_force.txt"
|
||||
register: copy_result_no_force_stat
|
||||
|
||||
- name: check that there was a change when not forcing file and dest does not exist
|
||||
assert:
|
||||
that:
|
||||
- copy_result_no_force|changed
|
||||
- copy_result_no_force_stat.stat.exists == True
|
||||
- copy_result_no_force_stat.stat.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
|
||||
|
||||
- name: make an output subdirectory
|
||||
win_file:
|
||||
path: "{{win_output_dir}}\\sub"
|
||||
state: directory
|
||||
|
||||
- name: test recursive copy to directory
|
||||
win_copy:
|
||||
src: subdir
|
||||
dest: "{{win_output_dir}}\\sub"
|
||||
register: recursive_copy_result
|
||||
|
||||
- name: get stats on files within sub directory
|
||||
win_find:
|
||||
paths: "{{win_output_dir}}\\sub"
|
||||
recurse: True
|
||||
register: recurse_find_results
|
||||
|
||||
- name: assert recursive copy worked
|
||||
assert:
|
||||
that:
|
||||
- recursive_copy_result|changed
|
||||
- recurse_find_results.examined == 7 # checks that it found 4 folders and 3 files
|
||||
|
||||
- name: test recursive copy to directory again
|
||||
win_copy:
|
||||
src: subdir
|
||||
dest: "{{win_output_dir}}\\sub"
|
||||
register: recursive_copy_result_again
|
||||
|
||||
- name: assert recursive copy worked
|
||||
assert:
|
||||
that:
|
||||
- not recursive_copy_result_again|changed
|
||||
|
||||
# Recursive folder copy with trailing slash (see issue 23559)
|
||||
|
||||
|
||||
- name: make an output subdirectory
|
||||
win_file:
|
||||
path: "{{win_output_dir}}\\subtrailing\\"
|
||||
state: directory
|
||||
|
||||
- name: test recursive copy to directory
|
||||
win_copy:
|
||||
src: subdir/
|
||||
dest: "{{win_output_dir}}\\subtrailing\\"
|
||||
register: recursive_copy_result2
|
||||
|
||||
- name: get stats on files within sub directory
|
||||
win_find:
|
||||
paths: "{{win_output_dir}}\\subtrailing\\"
|
||||
recurse: True
|
||||
register: recurse_find_results2
|
||||
|
||||
- name: assert recursive copy worked
|
||||
assert:
|
||||
that:
|
||||
- recursive_copy_result2|changed
|
||||
- recurse_find_results2.examined == 6 # checks that it found 3 folders and 3 files.
|
||||
# Note this is different from the test above because, by including the trailing
|
||||
# slash on the source, we only get the *contents* of the source folder
|
||||
# without the trailing slash, we would get the source folder *and* its
|
||||
# contents.
|
||||
# See 'src' parameter documentation
|
||||
# here: http://docs.ansible.com/ansible/win_copy_module.html
|
||||
|
||||
- name: test recursive copy to directory again with source slash
|
||||
win_copy:
|
||||
src: subdir/
|
||||
dest: "{{win_output_dir}}\\subtrailing\\"
|
||||
register: recursive_copy_result_again2
|
||||
|
||||
- name: assert recursive copy worked
|
||||
assert:
|
||||
that:
|
||||
- not recursive_copy_result_again2|changed
|
||||
|
||||
# test 'content' parameter
|
||||
- name: create file with content
|
||||
win_copy:
|
||||
content: abc
|
||||
dest: "{{win_output_dir}}\\content.txt"
|
||||
register: content_result
|
||||
|
||||
- name: get stat on creating file with content
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\content.txt"
|
||||
register: content_stat
|
||||
|
||||
- name: assert content copy worked
|
||||
assert:
|
||||
that:
|
||||
- content_result|changed
|
||||
- content_stat.stat.exists == True
|
||||
- content_stat.stat.checksum == 'a9993e364706816aba3e25717850c26c9cd0d89d'
|
||||
|
||||
- name: create file with content again
|
||||
win_copy:
|
||||
content: abc
|
||||
dest: "{{win_output_dir}}\\content.txt"
|
||||
register: content_result_again
|
||||
|
||||
- name: assert content copy again didn't change
|
||||
assert:
|
||||
that:
|
||||
- not content_result_again|changed
|
||||
|
||||
- name: copy file with different content
|
||||
win_copy:
|
||||
content: 123
|
||||
dest: "{{win_output_dir}}\\content.txt"
|
||||
register: content_different_result
|
||||
|
||||
- name: get stat on file with different content
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\content.txt"
|
||||
register: content_different_stat
|
||||
|
||||
- name: assert different content copy worked
|
||||
assert:
|
||||
that:
|
||||
- content_different_result|changed
|
||||
- content_different_stat.stat.checksum == '40bd001563085fc35165329ea1ff5c5ecbdbbeef'
|
||||
|
||||
- name: copy remote file
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\foo.txt"
|
||||
dest: "{{win_output_dir}}\\foobar.txt"
|
||||
remote_src: True
|
||||
register: remote_file_result
|
||||
|
||||
- name: get stat on new remote file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\foobar.txt"
|
||||
register: remote_file_stat
|
||||
|
||||
- name: assert remote copy worked
|
||||
assert:
|
||||
that:
|
||||
- remote_file_result|changed
|
||||
- remote_file_result.size == 8
|
||||
- remote_file_result.src == '{{win_output_dir|regex_replace('\\', '\\\\')}}\\foo.txt'
|
||||
- remote_file_result.dest == '{{win_output_dir|regex_replace('\\', '\\\\')}}\\foobar.txt'
|
||||
- remote_file_result.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- remote_file_result.operation == 'file_copy'
|
||||
- remote_file_result.original_basename == 'foo.txt'
|
||||
- remote_file_stat.stat.exists == True
|
||||
- remote_file_stat.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy remote file again
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\foo.txt"
|
||||
dest: "{{win_output_dir}}\\foobar.txt"
|
||||
remote_src: True
|
||||
register: remote_file_result_again
|
||||
|
||||
- name: assert remote copy again did not change
|
||||
assert:
|
||||
that:
|
||||
- not remote_file_result_again|changed
|
||||
|
||||
- name: copy remote folder
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\sub"
|
||||
dest: "{{win_output_dir}}\\sub2"
|
||||
remote_src: True
|
||||
register: remote_folder_result
|
||||
|
||||
- name: get stat on new remote folder contents
|
||||
win_find:
|
||||
paths: "{{win_output_dir}}\\sub2"
|
||||
recurse: True
|
||||
register: remote_folder_stat
|
||||
|
||||
- name: assert remote copy worked
|
||||
assert:
|
||||
that:
|
||||
- remote_folder_result|changed
|
||||
- remote_folder_result.size == 11
|
||||
- remote_folder_result.src == '{{win_output_dir|regex_replace('\\', '\\\\')}}\\sub'
|
||||
- remote_folder_result.dest == '{{win_output_dir|regex_replace('\\', '\\\\')}}\\sub2'
|
||||
- remote_folder_result.operation == 'folder_copy'
|
||||
- remote_folder_stat.examined == 8 # 5 folders 3 files
|
||||
|
||||
- name: copy remote folder again
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\sub"
|
||||
dest: "{{win_output_dir}}\\sub2"
|
||||
remote_src: True
|
||||
register: remote_folder_result_again
|
||||
|
||||
- name: assert remote copy again did not change
|
||||
assert:
|
||||
that:
|
||||
- not remote_folder_result_again|changed
|
||||
|
||||
- name: fail to copy when source doesn't exist
|
||||
win_copy:
|
||||
src: false-file
|
||||
dest: "{{win_output_dir}}\\fale-file.txt"
|
||||
register: fail_missing_source
|
||||
failed_when: not (fail_missing_source|failed)
|
||||
|
||||
- name: fail when copying remote src file when src doesn't exist
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\fake.txt"
|
||||
dest: "{{win_output_dir}}\\real.txt"
|
||||
remote_src: True
|
||||
register: fail_remote_missing_src
|
||||
failed_when: "fail_remote_missing_src.msg != 'Cannot copy src file: ' + win_output_dir + '\\\\fake.txt as it does not exist'"
|
||||
|
||||
- name: fail when copying remote src folder to file
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\sub"
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
remote_src: True
|
||||
register: fail_remote_folder_to_file
|
||||
failed_when: "'If src is a folder, dest must also be a folder. src' not in fail_remote_folder_to_file.msg"
|
||||
|
||||
- name: fail when copying remote src file to folder
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\foo.txt"
|
||||
dest: "{{win_output_dir}}\\sub"
|
||||
remote_src: True
|
||||
register: fail_remote_file_to_folder
|
||||
failed_when: "'If src is a file, dest must also be a file. src' not in fail_remote_file_to_folder.msg"
|
||||
|
||||
- name: run check mode copy new file
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: "{{win_output_dir}}\\foo-check.txt"
|
||||
register: check_copy_file
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on new file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\foo-check.txt"
|
||||
register: check_stat_file
|
||||
|
||||
- name: assert check would change but file doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- check_copy_file|changed
|
||||
- check_stat_file.stat.exists == False
|
||||
|
||||
- name: run check mode copy existing file
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
register: check_copy_file_existing
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check wouldn't change existing file
|
||||
assert:
|
||||
that:
|
||||
- not check_copy_file_existing|changed
|
||||
|
||||
- name: run check mode copy existing file with force False
|
||||
win_copy:
|
||||
src: empty.txt
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
force: False
|
||||
register: check_copy_existing_no_force
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check wouldn't change existing file
|
||||
assert:
|
||||
that:
|
||||
- not check_copy_existing_no_force|changed
|
||||
|
||||
- name: run check mode copy new file with force False
|
||||
win_copy:
|
||||
src: empty.txt
|
||||
dest: "{{win_output_dir}}\\no-force-check.txt"
|
||||
force: False
|
||||
register: check_copy_no_force
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on new file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\no-force-check.txt"
|
||||
register: check_copy_no_force_stat
|
||||
|
||||
- name: assert check wouldn't create file but change registered
|
||||
assert:
|
||||
that:
|
||||
- check_copy_no_force|changed
|
||||
- check_copy_no_force_stat.stat.exists == False
|
||||
|
||||
- name: run check mode copy new folder
|
||||
win_copy:
|
||||
src: subdir
|
||||
dest: "{{win_output_dir}}\\sub-check"
|
||||
register: check_copy_folder
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on new folder
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\sub-check"
|
||||
register: check_stat_folder
|
||||
|
||||
- name: assert check would change but folder doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- check_copy_folder|changed
|
||||
- check_stat_folder.stat.exists == False
|
||||
|
||||
- name: run check mode copy existing folder
|
||||
win_copy:
|
||||
src: subdir
|
||||
dest: "{{win_output_dir}}\\sub"
|
||||
register: check_copy_folder_existing
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check wouldn't change existing file
|
||||
assert:
|
||||
that:
|
||||
- not check_copy_folder_existing|changed
|
||||
|
||||
- name: run check mode copy new contents
|
||||
win_copy:
|
||||
content: abc
|
||||
dest: "{{win_output_dir}}\\content-check.txt"
|
||||
register: check_content_file
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on content file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\content-check.txt"
|
||||
register: check_stat_content
|
||||
|
||||
- name: assert check would change but content file doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- check_content_file|changed
|
||||
- check_stat_content.stat.exists == False
|
||||
|
||||
- name: run check mode copy existing contents
|
||||
win_copy:
|
||||
content: 123
|
||||
dest: "{{win_output_dir}}\\content.txt"
|
||||
register: check_content_file_existing
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check wouldn't change exisitng content file
|
||||
assert:
|
||||
that:
|
||||
- not check_content_file_existing|changed
|
||||
|
||||
- name: run check mode copy new contents
|
||||
win_copy:
|
||||
content: abc
|
||||
dest: "{{win_output_dir}}\\content.txt"
|
||||
register: check_different_content_file
|
||||
|
||||
- name: get stat on check mode file with different content
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\content.txt"
|
||||
register: check_different_content_stat
|
||||
|
||||
- name: assert check content changed but file wasn't touched
|
||||
assert:
|
||||
that:
|
||||
- check_different_content_file|changed
|
||||
|
||||
- name: run check mode copy new file remote src
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\foo.txt"
|
||||
dest: "{{win_output_dir}}\\foo-check.txt"
|
||||
remote_src: True
|
||||
register: check_copy_file_remote
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on new file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\foo-check.txt"
|
||||
register: check_stat_file_remote
|
||||
|
||||
- name: assert check would change but file doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- check_copy_file_remote|changed
|
||||
- check_stat_file_remote.stat.exists == False
|
||||
|
||||
- name: run check mode copy existing file remote src
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\foo.txt"
|
||||
dest: "{{win_output_dir}}\\foo.txt"
|
||||
remote_src: True
|
||||
register: check_copy_file_remote_existing
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check would change but file doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- not check_copy_file_remote_existing|changed
|
||||
|
||||
- name: run check mode copy new folder remote src
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\sub"
|
||||
dest: "{{win_output_dir}}\\sub-check"
|
||||
remote_src: True
|
||||
register: check_copy_folder_remote
|
||||
check_mode: yes
|
||||
|
||||
- name: get stat on new file
|
||||
win_stat:
|
||||
path: "{{win_output_dir}}\\sub-check"
|
||||
register: check_stat_folder_remote
|
||||
|
||||
- name: assert check would change but folder doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- check_copy_folder_remote|changed
|
||||
- check_stat_folder_remote.stat.exists == False
|
||||
|
||||
- name: run check mode copy existing folder remote src
|
||||
win_copy:
|
||||
src: "{{win_output_dir}}\\sub"
|
||||
dest: "{{win_output_dir}}\\sub2"
|
||||
remote_src: True
|
||||
register: check_copy_folder_remote_existing
|
||||
check_mode: yes
|
||||
|
||||
- name: assert check wouldn't change existing folder
|
||||
assert:
|
||||
that:
|
||||
- not check_copy_folder_remote_existing|changed
|
||||
|
||||
- name: cleanup output dir
|
||||
win_file:
|
||||
path: "{{win_output_dir}}"
|
||||
state: absent
|
||||
- block:
|
||||
- name: run tests for local to remote
|
||||
include_tasks: tests.yml
|
||||
|
||||
- name: run tests for remote to remote
|
||||
include_tasks: remote_tests.yml
|
||||
|
||||
always:
|
||||
- name: remove test folder
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}'
|
||||
state: absent
|
||||
|
|
414
test/integration/targets/win_copy/tasks/remote_tests.yml
Normal file
414
test/integration/targets/win_copy/tasks/remote_tests.yml
Normal file
|
@ -0,0 +1,414 @@
|
|||
---
|
||||
- name: fail when source does not exist remote
|
||||
win_copy:
|
||||
src: fakesource
|
||||
dest: fakedest
|
||||
remote_src: yes
|
||||
register: fail_remote_invalid_source
|
||||
failed_when: "fail_remote_invalid_source.msg != 'Cannot copy src file: fakesource as it does not exist'"
|
||||
|
||||
- name: setup source folder for remote tests
|
||||
win_copy:
|
||||
src: files/
|
||||
dest: '{{test_win_copy_path}}\source\'
|
||||
|
||||
- name: setup remote failure tests
|
||||
win_file:
|
||||
path: '{{item.path}}'
|
||||
state: '{{item.state}}'
|
||||
with_items:
|
||||
- { 'path': '{{test_win_copy_path}}\target\folder', 'state': 'directory' }
|
||||
- { 'path': '{{test_win_copy_path}}\target\file', 'state': 'touch' }
|
||||
- { 'path': '{{test_win_copy_path}}\target\subdir', 'state': 'touch' }
|
||||
|
||||
- name: fail source is a file but dest is a folder
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\folder'
|
||||
remote_src: yes
|
||||
register: fail_remote_file_to_folder
|
||||
failed_when: "'dest is already a folder' not in fail_remote_file_to_folder.msg"
|
||||
|
||||
- name: fail source is a file but dest is a folder
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\'
|
||||
dest: '{{test_win_copy_path}}\target\'
|
||||
remote_src: yes
|
||||
register: fail_remote_folder_to_file
|
||||
failed_when: "'dest is already a file' not in fail_remote_folder_to_file.msg"
|
||||
|
||||
- name: fail source is a file dest parent dir is also a file
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\file\foo.txt'
|
||||
remote_src: yes
|
||||
register: fail_remote_file_parent_dir_file
|
||||
failed_when: fail_remote_file_parent_dir_file.msg != 'object at destination parent dir ' + test_win_copy_path + '\\target\\file is currently a file'
|
||||
|
||||
- name: fail source is a folder dest parent dir is also a file
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\subdir'
|
||||
dest: '{{test_win_copy_path}}\target\file'
|
||||
remote_src: yes
|
||||
register: fail_remote_folder_parent_dir_file
|
||||
failed_when: "'object at dest parent dir is not a folder' not in fail_remote_folder_parent_dir_file.msg"
|
||||
|
||||
- name: fail to copy a remote file with parent dir that doesn't exist and filename is set
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\missing-dir\foo.txt'
|
||||
remote_src: yes
|
||||
register: fail_remote_missing_parent_dir
|
||||
failed_when: "'Destination directory ' + test_win_copy_path + '\\missing-dir does not exist' not in fail_remote_missing_parent_dir.msg"
|
||||
|
||||
- name: remove target after remote failure tests
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
state: absent
|
||||
|
||||
- name: create remote target after cleaning
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
state: directory
|
||||
|
||||
- name: copy single file remote (check mode)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\foo-target.txt'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file remote (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\foo-target.txt'
|
||||
register: remote_copy_file_actual_check
|
||||
|
||||
- name: assert copy single file remote (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file_check|changed
|
||||
- remote_copy_file_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file remote
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\foo-target.txt'
|
||||
remote_src: yes
|
||||
register: remote_copy_file
|
||||
|
||||
- name: get result of copy single file remote
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\foo-target.txt'
|
||||
register: remote_copy_file_actual
|
||||
|
||||
- name: assert copy single file remote
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file|changed
|
||||
- remote_copy_file.operation == 'file_copy'
|
||||
- remote_copy_file.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- remote_copy_file.size == 8
|
||||
- remote_copy_file.original_basename == 'foo.txt'
|
||||
- remote_copy_file_actual.stat.exists == True
|
||||
- remote_copy_file_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy single file remote (idempotent)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\foo-target.txt'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_again
|
||||
|
||||
- name: assert copy single file remote (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not remote_copy_file_again|changed
|
||||
|
||||
- name: copy single file into folder remote (check mode)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_to_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file into folder remote (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\foo.txt'
|
||||
register: remote_copy_file_to_folder_actual_check
|
||||
|
||||
- name: assert copy single file into folder remote (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file_to_folder_check|changed
|
||||
- remote_copy_file_to_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file into folder remote
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_to_folder
|
||||
|
||||
- name: get result of copy single file into folder remote
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\foo.txt'
|
||||
register: remote_copy_file_to_folder_actual
|
||||
|
||||
- name: assert copy single file into folder remote
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file_to_folder|changed
|
||||
- remote_copy_file_to_folder.operation == 'file_copy'
|
||||
- remote_copy_file_to_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- remote_copy_file_to_folder.size == 8
|
||||
- remote_copy_file_to_folder.original_basename == 'foo.txt'
|
||||
- remote_copy_file_to_folder_actual.stat.exists == True
|
||||
- remote_copy_file_to_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy single file into folder remote (idempotent)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_to_folder_again
|
||||
|
||||
- name: assert copy single file into folder remote
|
||||
assert:
|
||||
that:
|
||||
- not remote_copy_file_to_folder_again|changed
|
||||
|
||||
- name: copy single file to missing folder (check mode)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\missing\'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_to_missing_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file to missing folder remote (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\missing\foo.txt'
|
||||
register: remote_copy_file_to_missing_folder_actual_check
|
||||
|
||||
- name: assert copy single file to missing folder remote (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file_to_missing_folder_check|changed
|
||||
- remote_copy_file_to_missing_folder_check.operation == 'file_copy'
|
||||
- remote_copy_file_to_missing_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file to missing folder remote
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\foo.txt'
|
||||
dest: '{{test_win_copy_path}}\target\missing\'
|
||||
remote_src: yes
|
||||
register: remote_copy_file_to_missing_folder
|
||||
|
||||
- name: get result of copy single file to missing folder remote
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target\missing\foo.txt'
|
||||
register: remote_copy_file_to_missing_folder_actual
|
||||
|
||||
- name: assert copy single file to missing folder remote
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_file_to_missing_folder|changed
|
||||
- remote_copy_file_to_missing_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- remote_copy_file_to_missing_folder.operation == 'file_copy'
|
||||
- remote_copy_file_to_missing_folder.size == 8
|
||||
- remote_copy_file_to_missing_folder_actual.stat.exists == True
|
||||
- remote_copy_file_to_missing_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: clear target for folder to folder test
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
state: absent
|
||||
|
||||
- name: copy folder to folder remote (check mode)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_to_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy folder to folder remote (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
register: remote_copy_folder_to_folder_actual_check
|
||||
|
||||
- name: assert copy folder to folder remote (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_to_folder_check|changed
|
||||
- remote_copy_folder_to_folder_check.operation == 'folder_copy'
|
||||
- remote_copy_folder_to_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy folder to folder remote
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_to_folder
|
||||
|
||||
- name: get result of copy folder to folder remote
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\target'
|
||||
recurse: yes
|
||||
file_type: directory
|
||||
register: remote_copy_folder_to_folder_actual
|
||||
|
||||
- name: assert copy folder to folder remote
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_to_folder|changed
|
||||
- remote_copy_folder_to_folder.operation == 'folder_copy'
|
||||
- remote_copy_folder_to_folder_actual.examined == 11
|
||||
- remote_copy_folder_to_folder_actual.matched == 6
|
||||
- remote_copy_folder_to_folder_actual.files[0].filename == 'source'
|
||||
- remote_copy_folder_to_folder_actual.files[1].filename == 'subdir'
|
||||
- remote_copy_folder_to_folder_actual.files[2].filename == 'empty'
|
||||
- remote_copy_folder_to_folder_actual.files[3].filename == 'subdir2'
|
||||
- remote_copy_folder_to_folder_actual.files[4].filename == 'subdir3'
|
||||
- remote_copy_folder_to_folder_actual.files[5].filename == 'subdir4'
|
||||
|
||||
- name: copy folder to folder remote (idempotent)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_to_folder_again
|
||||
|
||||
- name: assert copy folder to folder remote (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not remote_copy_folder_to_folder_again|changed
|
||||
|
||||
- name: change remote file after folder to folder test
|
||||
win_copy:
|
||||
content: bar.txt
|
||||
dest: '{{test_win_copy_path}}\target\source\foo.txt'
|
||||
|
||||
- name: remote remote folder after folder to folder test
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target\source\subdir\subdir2\subdir3\subdir4'
|
||||
state: absent
|
||||
|
||||
- name: copy folder to folder remote after change
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_to_folder_after_change
|
||||
|
||||
- name: get result of copy folder to folder remote after change
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\target\source'
|
||||
recurse: yes
|
||||
patterns: ['foo.txt', 'qux.txt']
|
||||
register: remote_copy_folder_to_folder_after_change_actual
|
||||
|
||||
- name: assert copy folder after changes
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_to_folder_after_change|changed
|
||||
- remote_copy_folder_to_folder_after_change_actual.matched == 2
|
||||
- remote_copy_folder_to_folder_after_change_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
|
||||
- remote_copy_folder_to_folder_after_change_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: clear target folder before folder contents to remote test
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
state: absent
|
||||
|
||||
- name: copy folder contents to folder remote with backslash (check mode)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_content_backslash_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy folder contents to folder remote with backslash (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\target'
|
||||
register: remote_copy_folder_content_backslash_actual_check
|
||||
|
||||
- name: assert copy folder content to folder remote with backslash (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_content_backslash_check|changed
|
||||
- remote_copy_folder_content_backslash_actual_check.stat.exists == False
|
||||
|
||||
- name: copy folder contents to folder remote with backslash
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_content_backslash
|
||||
|
||||
- name: get result of copy folder contents to folder remote with backslash
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\target'
|
||||
recurse: yes
|
||||
file_type: directory
|
||||
register: remote_copy_folder_content_backslash_actual
|
||||
|
||||
- name: assert copy folder content to folder remote with backslash
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_content_backslash|changed
|
||||
- remote_copy_folder_content_backslash.operation == 'folder_copy'
|
||||
- remote_copy_folder_content_backslash_actual.examined == 10
|
||||
- remote_copy_folder_content_backslash_actual.matched == 5
|
||||
- remote_copy_folder_content_backslash_actual.files[0].filename == 'subdir'
|
||||
- remote_copy_folder_content_backslash_actual.files[1].filename == 'empty'
|
||||
- remote_copy_folder_content_backslash_actual.files[2].filename == 'subdir2'
|
||||
- remote_copy_folder_content_backslash_actual.files[3].filename == 'subdir3'
|
||||
- remote_copy_folder_content_backslash_actual.files[4].filename == 'subdir4'
|
||||
|
||||
- name: copy folder contents to folder remote with backslash (idempotent)
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}\source\'
|
||||
dest: '{{test_win_copy_path}}\target'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_content_backslash_again
|
||||
|
||||
- name: assert copy folder content to folder remote with backslash (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not remote_copy_folder_content_backslash_again|changed
|
||||
|
||||
- name: change remote file after folder content to folder test
|
||||
win_copy:
|
||||
content: bar.txt
|
||||
dest: '{{test_win_copy_path}}\target\foo.txt'
|
||||
|
||||
- name: remote remote folder after folder content to folder test
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\target\subdir\subdir2\subdir3\subdir4'
|
||||
state: absent
|
||||
|
||||
- name: copy folder content to folder remote after change
|
||||
win_copy:
|
||||
src: '{{test_win_copy_path}}/source/'
|
||||
dest: '{{test_win_copy_path}}/target/'
|
||||
remote_src: yes
|
||||
register: remote_copy_folder_content_to_folder_after_change
|
||||
|
||||
- name: get result of copy folder content to folder remote after change
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\target'
|
||||
recurse: yes
|
||||
patterns: ['foo.txt', 'qux.txt']
|
||||
register: remote_copy_folder_content_to_folder_after_change_actual
|
||||
|
||||
- name: assert copy folder content to folder after changes
|
||||
assert:
|
||||
that:
|
||||
- remote_copy_folder_content_to_folder_after_change|changed
|
||||
- remote_copy_folder_content_to_folder_after_change_actual.matched == 2
|
||||
- remote_copy_folder_content_to_folder_after_change_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
|
||||
- remote_copy_folder_content_to_folder_after_change_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
392
test/integration/targets/win_copy/tasks/tests.yml
Normal file
392
test/integration/targets/win_copy/tasks/tests.yml
Normal file
|
@ -0,0 +1,392 @@
|
|||
---
|
||||
- name: fail no source or content
|
||||
win_copy:
|
||||
dest: dest
|
||||
register: fail_no_source_content
|
||||
failed_when: fail_no_source_content.msg != 'src (or content) and dest are required'
|
||||
|
||||
- name: fail content but dest isn't a file, unix ending
|
||||
win_copy:
|
||||
content: a
|
||||
dest: a/
|
||||
register: fail_dest_not_file_unix
|
||||
failed_when: fail_dest_not_file_unix.msg != 'dest must be a file if content is defined'
|
||||
|
||||
- name: fail content but dest isn't a file, windows ending
|
||||
win_copy:
|
||||
content: a
|
||||
dest: a\
|
||||
register: fail_dest_not_file_windows
|
||||
failed_when: fail_dest_not_file_windows.msg != 'dest must be a file if content is defined'
|
||||
|
||||
- name: fail to copy a file with parent dir that doesn't exist and filename is set
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\missing-dir\foo.txt'
|
||||
register: fail_missing_parent_dir
|
||||
failed_when: "'Destination directory ' + test_win_copy_path + '\\missing-dir does not exist' not in fail_missing_parent_dir.msg"
|
||||
|
||||
- name: copy with content (check mode)
|
||||
win_copy:
|
||||
content: a
|
||||
dest: '{{test_win_copy_path}}\file'
|
||||
register: copy_content_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy with content (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\file'
|
||||
register: copy_content_actual_check
|
||||
|
||||
- name: assert copy with content (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_content_check|changed
|
||||
- copy_content_check.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
|
||||
- copy_content_check.operation == 'file_copy'
|
||||
- copy_content_check.size == 1
|
||||
- copy_content_actual_check.stat.exists == False
|
||||
|
||||
- name: copy with content
|
||||
win_copy:
|
||||
content: a
|
||||
dest: '{{test_win_copy_path}}\file'
|
||||
register: copy_content
|
||||
|
||||
- name: get result of copy with content
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\file'
|
||||
register: copy_content_actual
|
||||
|
||||
- name: assert copy with content
|
||||
assert:
|
||||
that:
|
||||
- copy_content|changed
|
||||
- copy_content.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
|
||||
- copy_content.operation == 'file_copy'
|
||||
- copy_content.size == 1
|
||||
- copy_content_actual.stat.exists == True
|
||||
- copy_content_actual.stat.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
|
||||
|
||||
- name: copy with content (idempotent)
|
||||
win_copy:
|
||||
content: a
|
||||
dest: '{{test_win_copy_path}}\file'
|
||||
register: copy_content_again
|
||||
|
||||
- name: assert copy with content (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not copy_content_again|changed
|
||||
|
||||
- name: copy with content change when missing
|
||||
win_copy:
|
||||
content: b
|
||||
dest: '{{test_win_copy_path}}\file'
|
||||
force: no
|
||||
register: copy_content_when_missing
|
||||
|
||||
- name: assert copy with content change when missing
|
||||
assert:
|
||||
that:
|
||||
- not copy_content_when_missing|changed
|
||||
|
||||
- name: copy single file (check mode)
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\foo-target.txt'
|
||||
register: copy_file_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\foo-target.txt'
|
||||
register: copy_file_actual_check
|
||||
|
||||
- name: assert copy single file (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_file_check|changed
|
||||
- copy_file_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file_check.operation == 'file_copy'
|
||||
- copy_file_check.size == 8
|
||||
- copy_file_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\foo-target.txt'
|
||||
register: copy_file
|
||||
|
||||
- name: get result of copy single file
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\foo-target.txt'
|
||||
register: copy_file_actual
|
||||
|
||||
- name: assert copy single file
|
||||
assert:
|
||||
that:
|
||||
- copy_file|changed
|
||||
- copy_file.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file.operation == 'file_copy'
|
||||
- copy_file.size == 8
|
||||
- copy_file_actual.stat.exists == True
|
||||
- copy_file_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy single file (idempotent)
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\foo-target.txt'
|
||||
register: copy_file_again
|
||||
|
||||
- name: assert copy single file (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not copy_file_again|changed
|
||||
|
||||
- name: copy single file to folder (check mode)
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\'
|
||||
register: copy_file_to_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file to folder (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\foo.txt'
|
||||
register: copy_file_to_folder_actual_check
|
||||
|
||||
- name: assert copy single file to folder (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_file_to_folder_check|changed
|
||||
- copy_file_to_folder_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file_to_folder_check.operation == 'file_copy'
|
||||
- copy_file_to_folder_check.size == 8
|
||||
- copy_file_to_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file to folder
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\'
|
||||
register: copy_file_to_folder
|
||||
|
||||
- name: get result of copy single file to folder
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\foo.txt'
|
||||
register: copy_file_to_folder_actual
|
||||
|
||||
- name: assert copy single file to folder
|
||||
assert:
|
||||
that:
|
||||
- copy_file_to_folder|changed
|
||||
- copy_file_to_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file_to_folder.operation == 'file_copy'
|
||||
- copy_file_to_folder.size == 8
|
||||
- copy_file_to_folder_actual.stat.exists == True
|
||||
- copy_file_to_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy single file to folder (idempotent)
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\'
|
||||
register: copy_file_to_folder_again
|
||||
|
||||
- name: assert copy single file to folder (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not copy_file_to_folder_again|changed
|
||||
|
||||
- name: copy single file to missing folder (check mode)
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\missing\'
|
||||
register: copy_file_to_missing_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy single file to missing folder (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\missing\foo.txt'
|
||||
register: copy_file_to_missing_folder_actual_check
|
||||
|
||||
- name: assert copy single file to missing folder (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_file_to_missing_folder_check|changed
|
||||
- copy_file_to_missing_folder_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file_to_missing_folder_check.operation == 'file_copy'
|
||||
- copy_file_to_missing_folder_check.size == 8
|
||||
- copy_file_to_missing_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy single file to missing folder
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\missing\'
|
||||
register: copy_file_to_missing_folder
|
||||
|
||||
- name: get result of copy single file to missing folder
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\missing\foo.txt'
|
||||
register: copy_file_to_missing_folder_actual
|
||||
|
||||
- name: assert copy single file to missing folder
|
||||
assert:
|
||||
that:
|
||||
- copy_file_to_missing_folder|changed
|
||||
- copy_file_to_missing_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
- copy_file_to_missing_folder.operation == 'file_copy'
|
||||
- copy_file_to_missing_folder.size == 8
|
||||
- copy_file_to_missing_folder_actual.stat.exists == True
|
||||
- copy_file_to_missing_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy folder (check mode)
|
||||
win_copy:
|
||||
src: files
|
||||
dest: '{{test_win_copy_path}}\recursive\folder'
|
||||
register: copy_folder_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy folder (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\recursive\folder'
|
||||
register: copy_folder_actual_check
|
||||
|
||||
- name: assert copy folder (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_folder_check|changed
|
||||
- copy_folder_check.operation == 'folder_copy'
|
||||
- copy_folder_actual_check.stat.exists == False
|
||||
|
||||
- name: copy folder
|
||||
win_copy:
|
||||
src: files
|
||||
dest: '{{test_win_copy_path}}\recursive\folder'
|
||||
register: copy_folder
|
||||
|
||||
- name: get result of copy folder
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\recursive\folder'
|
||||
recurse: yes
|
||||
file_type: directory
|
||||
register: copy_folder_actual
|
||||
|
||||
- name: assert copy folder
|
||||
assert:
|
||||
that:
|
||||
- copy_folder|changed
|
||||
- copy_folder.operation == 'folder_copy'
|
||||
- copy_folder_actual.examined == 11 # includes files and folders, the below is the nested order
|
||||
- copy_folder_actual.matched == 6
|
||||
- copy_folder_actual.files[0].filename == 'files'
|
||||
- copy_folder_actual.files[1].filename == 'subdir'
|
||||
- copy_folder_actual.files[2].filename == 'empty'
|
||||
- copy_folder_actual.files[3].filename == 'subdir2'
|
||||
- copy_folder_actual.files[4].filename == 'subdir3'
|
||||
- copy_folder_actual.files[5].filename == 'subdir4'
|
||||
|
||||
- name: copy folder (idempotent)
|
||||
win_copy:
|
||||
src: files
|
||||
dest: '{{test_win_copy_path}}\recursive\folder'
|
||||
register: copy_folder_again
|
||||
|
||||
- name: assert copy folder (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not copy_folder_again|changed
|
||||
|
||||
- name: change the text of a file in the remote source
|
||||
win_copy:
|
||||
content: bar.txt
|
||||
dest: '{{test_win_copy_path}}\recursive\folder\files\foo.txt'
|
||||
|
||||
- name: remove folder for test of recursive copy
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}\recursive\folder\files\subdir\subdir2\subdir3\subdir4'
|
||||
state: absent
|
||||
|
||||
- name: copy folder after changes
|
||||
win_copy:
|
||||
src: files
|
||||
dest: '{{test_win_copy_path}}\recursive\folder'
|
||||
register: copy_folder_after_change
|
||||
|
||||
- name: get result of copy folder after changes
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\recursive\folder\files'
|
||||
recurse: yes
|
||||
patterns: ['foo.txt', 'qux.txt']
|
||||
register: copy_folder_after_changes_actual
|
||||
|
||||
- name: assert copy folder after changes
|
||||
assert:
|
||||
that:
|
||||
- copy_folder_after_change|changed
|
||||
- copy_folder_after_changes_actual.matched == 2
|
||||
- copy_folder_after_changes_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
|
||||
- copy_folder_after_changes_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
|
||||
|
||||
- name: copy folder's contents (check mode)
|
||||
win_copy:
|
||||
src: files/
|
||||
dest: '{{test_win_copy_path}}\recursive-contents\'
|
||||
register: copy_folder_contents_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of copy folder'scontents (check mode)
|
||||
win_stat:
|
||||
path: '{{test_win_copy_path}}\recursive-contents'
|
||||
register: copy_folder_contents_actual_check
|
||||
|
||||
- name: assert copy folder's contents (check mode)
|
||||
assert:
|
||||
that:
|
||||
- copy_folder_contents_check|changed
|
||||
- copy_folder_contents_check.operation == 'folder_copy'
|
||||
- copy_folder_contents_actual_check.stat.exists == False
|
||||
|
||||
- name: copy folder's contents
|
||||
win_copy:
|
||||
src: files/
|
||||
dest: '{{test_win_copy_path}}\recursive-contents\'
|
||||
register: copy_folder_contents
|
||||
|
||||
- name: get result of copy folder
|
||||
win_find:
|
||||
paths: '{{test_win_copy_path}}\recursive-contents'
|
||||
recurse: yes
|
||||
file_type: directory
|
||||
register: copy_folder_contents_actual
|
||||
|
||||
- name: assert copy folder
|
||||
assert:
|
||||
that:
|
||||
- copy_folder_contents|changed
|
||||
- copy_folder_contents.operation == 'folder_copy'
|
||||
- copy_folder_contents_actual.examined == 10 # includes files and folders, the below is the nested order
|
||||
- copy_folder_contents_actual.matched == 5
|
||||
- copy_folder_contents_actual.files[0].filename == 'subdir'
|
||||
- copy_folder_contents_actual.files[1].filename == 'empty'
|
||||
- copy_folder_contents_actual.files[2].filename == 'subdir2'
|
||||
- copy_folder_contents_actual.files[3].filename == 'subdir3'
|
||||
- copy_folder_contents_actual.files[4].filename == 'subdir4'
|
||||
|
||||
- name: fail to copy file to a folder
|
||||
win_copy:
|
||||
src: foo.txt
|
||||
dest: '{{test_win_copy_path}}\recursive-contents'
|
||||
register: fail_file_to_folder
|
||||
failed_when: "'object at path is already a directory' not in fail_file_to_folder.msg"
|
||||
|
||||
- name: fail to copy folder to a file
|
||||
win_copy:
|
||||
src: subdir/
|
||||
dest: '{{test_win_copy_path}}\recursive-contents\foo.txt'
|
||||
register: fail_folder_to_file
|
||||
failed_when: "'object at parent directory path is already a file' not in fail_folder_to_file.msg"
|
||||
|
||||
- name: remove test folder after local to remote tests
|
||||
win_file:
|
||||
path: '{{test_win_copy_path}}'
|
||||
state: absent
|
Loading…
Add table
Add a link
Reference in a new issue