diff options
author | PRASOON KARUNAN V <12897753+kvprasoon@users.noreply.github.com> | 2023-05-10 04:28:22 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 08:58:22 +1000 |
commit | b576f0cda7aad938d1eab032608a79a30a6a4968 (patch) | |
tree | 4a710db81267b2f4db9c786bc697f8c32c5983bb | |
parent | 7ef8e0e102388ae422b214eccffc381deeecadf1 (diff) | |
download | ansible-b576f0cda7aad938d1eab032608a79a30a6a4968.tar.gz |
fix error if path had wildcard in it (#74723)
* fix error if path had wildcard in it
* add test
* add changelog fragment
-rw-r--r-- | changelogs/fragments/74723-support-wildcard-win_fetch.yml | 3 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/winrm.py | 4 | ||||
-rw-r--r-- | test/integration/targets/win_fetch/tasks/main.yml | 15 |
3 files changed, 20 insertions, 2 deletions
diff --git a/changelogs/fragments/74723-support-wildcard-win_fetch.yml b/changelogs/fragments/74723-support-wildcard-win_fetch.yml new file mode 100644 index 0000000000..e794213282 --- /dev/null +++ b/changelogs/fragments/74723-support-wildcard-win_fetch.yml @@ -0,0 +1,3 @@ +bugfixes: +- win_fetch - Add support for using file with wildcards in file name. + (https://github.com/ansible/ansible/issues/73128) diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index 2b79dcea81..bfb2182c60 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -714,7 +714,7 @@ class Connection(ConnectionBase): try: script = ''' $path = '%(path)s' - If (Test-Path -Path $path -PathType Leaf) + If (Test-Path -LiteralPath $path -PathType Leaf) { $buffer_size = %(buffer_size)d $offset = %(offset)d @@ -729,7 +729,7 @@ class Connection(ConnectionBase): } $stream.Close() > $null } - ElseIf (Test-Path -Path $path -PathType Container) + ElseIf (Test-Path -LiteralPath $path -PathType Container) { Write-Host "[DIR]"; } diff --git a/test/integration/targets/win_fetch/tasks/main.yml b/test/integration/targets/win_fetch/tasks/main.yml index 78b6fa02c9..b0c6cad8be 100644 --- a/test/integration/targets/win_fetch/tasks/main.yml +++ b/test/integration/targets/win_fetch/tasks/main.yml @@ -210,3 +210,18 @@ - fetch_special_file.checksum == '34d4150adc3347f1dd8ce19fdf65b74d971ab602' - fetch_special_file.dest == host_output_dir + "/abc$not var'quote‘" - fetch_special_file_actual.stdout == 'abc' + +- name: create file with wildcard characters + raw: Set-Content -LiteralPath '{{ remote_tmp_dir }}\abc[].txt' -Value 'abc' + +- name: fetch file with wildcard characters + fetch: + src: '{{ remote_tmp_dir }}\abc[].txt' + dest: '{{ host_output_dir }}/' + register: fetch_wildcard_file_nofail + +- name: assert fetch file with wildcard characters + assert: + that: + - "fetch_wildcard_file_nofail is not failed" + |