1

Let's assume I have a textfile in some network path

EX: \cr-ampd-a01.abcd.loc\BulkFolder\textfile.txt

How to copy that file to my controller machine in ansible

Note: I can access it by (WIN+R and that path) then it pops up for credentials to access.

This is the sample code with win_copy

- name: copy from network to controller
  win_copy:
    src: \\cr-ampd-a01.abcd.loc\BulkFolder\textfile.txt
    dest: C:\Temp\OTW\Mastapps
    remote_src: yes
    become: yes
  vars:
    ansible_become_user: XXX\Uxxxxxx
    ansible_become_pass: PasswordHere

Error with this code is: Cannot copy src file as it does not exit

Another with net_get

  - name: copy from network to controller
    net_get:
      src: \\cr-ampd-a01.abcd.loc\BulkFolder\textfile.txt
      dest: C:\Temp\OTW\Mastapps
      ansible_network_os: "eos"
      remote_src: True
      become: True
    vars:
      ansible_become_user: XXX\Uxxxxxx
      ansible_become_pass: PasswordHere

Error here: ansible_network_os must be specified on this host

How can I achieve this?

1 Answers1

0

You try to copy a file from a CIFS resource. I'm relative sure that this isn't working with copy or win_copy because they are used to copy file on that (physical) machine. Because CIFS is a protocol like HTTP and FTP you need a client to get the file from the remote machine. As you also wrote, you need to identify yourself with some credentials, the win_copy task doesnt have that option.

One option could be - mount the network device to -for example- N:/ or something like that and use then win_copy with N:/source.txt - in that case the N:-drive is like C:/ or D:/ a known path on the machine. Have a look at win_share - https://docs.ansible.com/ansible/latest/modules/win_share_module.html

Another option is to call a local CIFS client via command like command: copy //server/path/file c:/file or robocopy, but that isn't easy to be idempotent. See Copy files to network computers on windows command line

net_get is useful to copy files from "network devices" - please have a look at https://docs.ansible.com/ansible/latest/network/user_guide/platform_index.html#platform-options for a list of supported platforms. As of the list - I would say coping from a CIFS-share is not supported by net_get.

TRW
  • 876
  • 7
  • 23