Ansible win_copy模块从Linux复制文件到Windows失败问题排查
Let's break down why you're seeing this error and how to fix it:
1. Incorrect remote_src Parameter Usage
You've set remote_src: yes in your win_copy task, but this parameter tells Ansible to look for the source file on the remote Windows server, not your Linux control node. Since Windows doesn't use Linux-style paths like /home/app/..., Ansible can't find the file there.
When copying files from your control node to a Windows remote, you should omit remote_src entirely (it defaults to no, which means "source is on the control node") or explicitly set remote_src: no.
2. Mismatched Source File Path
Looking at your error log and the ls output:
- Your task's
srcis set to/home/app/backup/1//de85cfa1-cb41-53ca-aba0-0e3dd728c27b//test.zip - But the actual file exists at
/home/app/1//de85cfa1-cb41-53ca-aba0-0e3dd728c27b//test.zip
You have an extra backup directory in your task's source path, which is why Ansible can't locate the file.
Corrected Playbook Task
Here's the fixed version of your task, addressing both issues:
- name: Copy file to windows remote win_copy : src: "/home/app/1/de85cfa1-cb41-53ca-aba0-0e3dd728c27b/test.zip" dest: "c:/my_app_home/"
(Note: The double slashes // in your path work on Linux, but using single slashes / is more clean and standard.)
Additional Notes
- If you ever need to copy a file between two locations on the Windows server itself, that's when you'd use
remote_src: yes. - Always double-check that your
srcpath matches exactly where the file lives on your Linux control node—even a single extra directory will cause this "file not found" error.
内容的提问来源于stack exchange,提问作者user63898

