Julia Chen
Julia Chen

Reputation: 43

ansible win_copy does not work "error: src file does not exist"

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"}

I'm sure file X:\\assets\\audio.mp3 exists, and X:\ is a shared file of the linux control machine.

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\

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

this task can be run successfully!

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!

Upvotes: 2

Views: 4240

Answers (2)

Risshe
Risshe

Reputation: 21

Remove

remote_src: true

This line is checking for the file on your client machine .

Upvotes: 2

Random_Automation
Random_Automation

Reputation: 452

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

`

Upvotes: 0

Related Questions