diff --git a/lib/ansible/plugins/action/win_copy.py b/lib/ansible/plugins/action/win_copy.py index 71601fdfd7..55b61c2526 100644 --- a/lib/ansible/plugins/action/win_copy.py +++ b/lib/ansible/plugins/action/win_copy.py @@ -473,6 +473,8 @@ class ActionModule(ActionBase): symlinks=source_files['symlinks'] ) ) + # src is not required for query, will fail path validation is src has unix allowed chars + query_args.pop('src', None) query_args.pop('content', None) query_return = self._execute_module(module_args=query_args, task_vars=task_vars) diff --git a/test/integration/targets/win_copy/files-vault/folder/nested-vault-file b/test/integration/targets/win_copy/files-different/vault/folder/nested-vault-file similarity index 100% rename from test/integration/targets/win_copy/files-vault/folder/nested-vault-file rename to test/integration/targets/win_copy/files-different/vault/folder/nested-vault-file diff --git a/test/integration/targets/win_copy/files-vault/readme.txt b/test/integration/targets/win_copy/files-different/vault/readme.txt similarity index 100% rename from test/integration/targets/win_copy/files-vault/readme.txt rename to test/integration/targets/win_copy/files-different/vault/readme.txt diff --git a/test/integration/targets/win_copy/files-vault/vault-file b/test/integration/targets/win_copy/files-different/vault/vault-file similarity index 100% rename from test/integration/targets/win_copy/files-vault/vault-file rename to test/integration/targets/win_copy/files-different/vault/vault-file diff --git a/test/integration/targets/win_copy/tasks/tests.yml b/test/integration/targets/win_copy/tasks/tests.yml index 04e2ca5829..a061e97412 100644 --- a/test/integration/targets/win_copy/tasks/tests.yml +++ b/test/integration/targets/win_copy/tasks/tests.yml @@ -28,7 +28,7 @@ - name: fail to copy an encrypted file without the password set win_copy: - src: '{{role_path}}/files-vault/vault-file' + src: '{{role_path}}/files-different/vault/vault-file' dest: '{{test_win_copy_path}}\file' register: fail_copy_encrypted_file ignore_errors: yes # weird failed_when doesn't work in this case @@ -37,11 +37,11 @@ assert: that: - fail_copy_encrypted_file|failed - - fail_copy_encrypted_file.msg == 'A vault password or secret must be specified to decrypt {{role_path}}/files-vault/vault-file' + - fail_copy_encrypted_file.msg == 'A vault password or secret must be specified to decrypt {{role_path}}/files-different/vault/vault-file' - name: fail to copy a directory with an encrypted file without the password win_copy: - src: '{{role_path}}/files-vault' + src: '{{role_path}}/files-different/vault' dest: '{{test_win_copy_path}}' register: fail_copy_directory_with_enc_file ignore_errors: yes @@ -50,7 +50,7 @@ assert: that: - fail_copy_directory_with_enc_file|failed - - fail_copy_directory_with_enc_file.msg == 'A vault password or secret must be specified to decrypt {{role_path}}/files-vault/vault-file' + - fail_copy_directory_with_enc_file.msg == 'A vault password or secret must be specified to decrypt {{role_path}}/files-different/vault/vault-file' - name: copy with content (check mode) win_copy: @@ -412,6 +412,37 @@ register: fail_folder_to_file failed_when: "'object at parent directory path is already a file' not in fail_folder_to_file.msg" +# https://github.com/ansible/ansible/issues/31336 +- name: create file with colon in the name + copy: + dest: '{{role_path}}/files-different/colon:file' + content: test + delegate_to: localhost + +- name: copy a file with colon as a source + win_copy: + src: '{{role_path}}/files-different/colon:file' + dest: '{{test_win_copy_path}}\colon.file' + register: copy_file_with_colon + +- name: get result of file with colon as a source + win_stat: + path: '{{test_win_copy_path}}\colon.file' + register: copy_file_with_colon_result + +- name: assert results of copy a file with colon as a source + assert: + that: + - copy_file_with_colon|changed + - copy_file_with_colon_result.stat.exists == True + - copy_file_with_colon_result.stat.checksum == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" + +- name: remove file with colon in the name + file: + path: '{{role_path}}/files-different/colon:file' + state: absent + delegate_to: localhost + - name: remove test folder after local to remote tests win_file: path: '{{test_win_copy_path}}'