You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ansible/PowerShell fails with the message below. The reason seems to be fairly straightforward as well.
Here the module runs Get-ChildItem against the source, which is an empty folder and thus will return nothing. In turn the loop in the next line will not run and never call the Copy-Folder function, which would create the new folder at dest.
A few lines further down $result.size = Get-FileSize -Path $remote_dest will fail, since there is nothing to check.
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at Microsoft.PowerShell.Commands.GetItemCommand.ProcessRecord()
fatal: [<redacted>]: FAILED! => {"changed": false, "dest": "C:\\emptyDir2\\", "msg": "Unhandled exception while executing module: Cannot find path 'C:\\emptyDir2\\' because it does not exist.", "src": "C:\\emptyDir\\"}
The text was updated successfully, but these errors were encountered:
The setup below may be a solution in some cases, as it copies the entire src folder (no trailing slash in src) and does create dest.
ansible.windows.win_copy:
remote_src: truesrc: C:\dir1\emptyDirdest: C:\dir2\ # does not exist yet
Unfortunately in my case I have no control over the actual name of emptyDir or its potential content (acutal values come from win_find), but need its content to be in a folder called emptyDir2.
I'm aware that I can work around this issue by ensuring dest exists using win_file: state=directory, but the documentation reads as if it should be possible with a single task. And I'd really appreciate if it did, because otherwise I'll have to start guarding against this edge case with win_file in multiple projects. :)
SUMMARY
win_copy fails remote copy of empty source folder to a non-existent dest folder
ISSUE TYPE
COMPONENT NAME
win_copy
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Tested on Windows Server 2019
STEPS TO REPRODUCE
Create an empty folder and try to copy it to a non-existent folder on the same remote machine, having both paths end with slashes.
According to the documentation, this should create an empty folder at
dest
EXPECTED RESULTS
An empty folder is created.
ACTUAL RESULTS
Ansible/PowerShell fails with the message below. The reason seems to be fairly straightforward as well.
Here the module runs
Get-ChildItem
against the source, which is an empty folder and thus will return nothing. In turn the loop in the next line will not run and never call theCopy-Folder
function, which would create the new folder atdest
.A few lines further down
$result.size = Get-FileSize -Path $remote_dest
will fail, since there is nothing to check.The text was updated successfully, but these errors were encountered: