ansible win_copy无法正常工作“错误:src文件不存在" [英] ansible win_copy does not work "error: src file does not exist"
问题描述
我尝试使用以下剧本将mp3文件复制到D:\
I try to use the following playbook to copy a mp3 file to D:\
- name: copy file
hosts: windows
- name: copy file to D:
win_copy:
src: X:\assets\audio.mp3
dest: D:\template\
remote_src: yes
但是我收到以下错误消息:
but I get the following error message:
TASK [Gathering Facts]**********************************************
ok: [111.111.23.40]
TASK [copy file to D:] ********************************
fatal: [111.231.76.40]: FAILED! => {"changed": false, "dest":
"D:\\template\\", "msg": "Cannot copy src file: 'X:\\assets\\audio.mp3'
as it does not exist", "src": "X:\\assets\\audio.mp3"}
我确定文件X:\\assets\\audio.mp3
存在,并且X:\
是Linux控制计算机的共享文件.
I'm sure file X:\\assets\\audio.mp3
exists, and X:\
is a shared file of the linux control machine.
您可以在此目录构造函数中看到src文件 当我上传Windows机器并运行
you can see the src file in this directory structor When I upload the windows machine and run
copy X:\assets\audio.mp3 D:\template\
在cmd.exe中,可以成功复制audio.mp3!我还尝试在Windows计算机上复制另一个文件,例如:
in the cmd.exe, the audio.mp3 can successfully be copied! I also tried to copy another file on the windows machine, for example:
- name: copy file
hosts: windows
- name: copy template to D:
win_copy:
src: D:\document\test.txt
dest: D:\template\
remote_src: yes
此任务可以成功运行!
我尝试了其他方法,例如
And I tried other way, for example
- name: copy file
hosts: windows
- name: copy template to D:
win_command: cmd.exe /k copy X:\assets\audio.mp3 D:\template\
没有错误,但是我无法获得复制的文件!这真的让我分心了!
there is no error, but I can't get the copied file! This really distract me!
推荐答案
您都将创建执行映射和复制的powershell脚本.然后,您可以使用ansible通过powershell脚本执行任务.
Either you create a powershell script which does the mapping and copying. And then you use ansible to perform your task using thr powershell script.
另一种方式(这里假设源服务器和目标服务器都在同一域中)
The other way (Here assuming that both source and destination servers are on same domain )
- name: copy files
win_copy:
src: \\domain_server\c$\somefile.txt
dest: c:\Dir\somefile.txt
remote_src: true
`
这篇关于ansible win_copy无法正常工作“错误:src文件不存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!