【问题标题】:ansible win_copy does not work "error: src file does not exist"ansible win_copy 不起作用“错误:src 文件不存在”
【发布时间】:2018-07-13 03:57:58
【问题描述】:

我尝试使用以下 playbook 将 mp3 文件复制到 D:\

- name: copy file
  hosts: windows
  - name: copy file to D:
    win_copy:
      src: X:\assets\audio.mp3
      dest: D:\template\
      remote_src: yes

但我收到以下错误消息:

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中控机的共享文件。

you can see the src file in this directory structor 当我上传windows机器并运行时

copy X:\assets\audio.mp3 D:\template\

在cmd.exe中,可以成功复制audio.mp3!我还尝试在windows机器上复制另一个文件,例如:

- name: copy file
  hosts: windows
  - name: copy template to D:
    win_copy:
      src: D:\document\test.txt
      dest: D:\template\
      remote_src: yes

此任务可以成功运行!

我尝试了其他方式,例如

- name: copy file
  hosts: windows
  - name: copy template to D:
    win_command: cmd.exe /k copy X:\assets\audio.mp3 D:\template\

没有错误,但我无法获取复制的文件!这真的让我分心!

【问题讨论】:

  • 检查您的文件权限。如果您的 mp3 文件和父目录具有正确的权限。您也可以使用 -vvvv 命令以详细模式运行 ansible

标签: ansible


【解决方案1】:

您可以创建一个执行映射和复制的 powershell 脚本。然后你使用 ansible 使用 thr powershell 脚本执行你的任务。

另一种方式(这里假设源服务器和目标服务器都在同一个域上)

     - name: copy files
       win_copy:
          src: \\domain_server\c$\somefile.txt
          dest: c:\Dir\somefile.txt
          remote_src: true

`

【讨论】:

  • 我试过你的方法,没有报错,TASK【在F下创建映射驱动】********************** ok :[111.111.20.40]任务[复制文件] *************************************** ******更改:[111.111.20.40] 但它也没有工作!复制命令没有成功执行
  • 这可能很棘手!!您使用的是什么身份验证方法?
【解决方案2】:

删除

remote_src: true

这一行正在检查您的客户端计算机上的文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 2014-09-21
    • 2013-01-15
    • 2011-11-01
    相关资源
    最近更新 更多