The win_copy module in 2.4.0.0 fails if src contains a ":" character #31336
Labels
affects_2.4
This issue/PR affects Ansible v2.4
bug
This issue/PR relates to a bug.
module
This issue/PR relates to a module.
support:core
This issue/PR relates to code supported by the Ansible Engineering Team.
windows
Windows community
Milestone
ISSUE TYPE
COMPONENT NAME
win_copy
ANSIBLE VERSION
CONFIGURATION
None
OS / ENVIRONMENT
Linux control machine managing Windows hosts.
SUMMARY
We store managed Windows files on the Linux control machine using paths that contain c:, d: etc which allows simple copying. This works fine with ansible < 2.4.0.0 but stops working in 2.4.0.0. Details below.
STEPS TO REPRODUCE
EXPECTED RESULTS
Copy should work, just like it did in ansible before 2.4.0.0.
ACTUAL RESULTS
Copy fails with an error "Get-AnsibleParam: Parameter 'src' has an invalid path '/tmp/c:/temp/test.txt' specified.".
ANALYSIS
Copying files using win_copy fails if the source path (on the control host running Linux) contains a ":" character. Disabling the $src parameter validation in win_copy.ps1 (i.e removing -type 'path' from the Get-AnsibleParam call) allows the copy to work. This is our temporary workaround, but this will probably cause a number of other problems.
The root cause seems to lie in the Get-AnsibleParam function in ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1. The check "Test-Path -IsValid" is where we believe it fails. For example, running "Test-Path -IsValid /tmp/c:/test.txt" in powershell returns $False.
The win_copy module has been greatly improved since 2.3.0.0. I am guessing the Test-Path -IsValid code was never reached in the previous versions, maybe because $src was left empty since it is not really needed on the remote end for a normal copy? I tried "transplanting" the 2.3.0.0 win_copy.ps1 module into 2.4.0.0, but got the same error, which is why I think there has been a change of how the parameters are supplied during the invocation of the win_copy module.
I am not quite sure of the best way to fix this in the code. We need to somehow make sure that win_copy.ps1 never tries to validate a path that actually references something on the control machine.
The text was updated successfully, but these errors were encountered: