How to copy a file from windows to linux

220 views
Skip to first unread message

bulent senguler

unread,
Jun 25, 2021, 3:41:26 PM6/25/21
to Ansible Project
Hi all,
I want to copy a file from windows to linux but I cannot do that. I trıed win_copy module and remote_src=yes and job was success but the file did not exist on target machine.  Where I am wrong. Thanks for helps.

Wei-Yen Tan

unread,
Jun 25, 2021, 3:42:56 PM6/25/21
to ansible...@googlegroups.com
Slurp to ansible controller then copy to linux 

From: ansible...@googlegroups.com <ansible...@googlegroups.com> on behalf of bulent senguler <bulents...@gmail.com>
Sent: Saturday, June 26, 2021 7:41:26 AM
To: Ansible Project <ansible...@googlegroups.com>
Subject: [ansible-project] How to copy a file from windows to linux
 
Hi all,
I want to copy a file from windows to linux but I cannot do that. I trıed win_copy module and remote_src=yes and job was success but the file did not exist on target machine.  Where I am wrong. Thanks for helps.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b724b3ea-8f0c-4a73-8f91-94530808a8ean%40googlegroups.com.

bulent senguler

unread,
Jun 25, 2021, 4:25:00 PM6/25/21
to Ansible Project
Actually, as a same result.

25 Haziran 2021 Cuma tarihinde saat 22:42:56 UTC+3 itibarıyla weiye...@gmail.com şunları yazdı:

Wei-Yen Tan

unread,
Jun 25, 2021, 4:28:52 PM6/25/21
to ansible...@googlegroups.com
What do yoy mean. Is it doing the same thing? Can you please share play book and task?

Sent: Saturday, June 26, 2021 8:25:00 AM
To: Ansible Project <ansible...@googlegroups.com>
Subject: Re: [ansible-project] How to copy a file from windows to linux
 

bulent senguler

unread,
Jun 25, 2021, 4:57:56 PM6/25/21
to Ansible Project
- name: copy file from windows to tower
  copy_win:
    src : c:\tmp\b.txt
     dest: /tmp
  remote_src: yes


output :

{
    "src": "c:\\test\\b.txt",
    "_ansible_no_log": false,
    "dest": "/tmp",
    "checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
    "changed": true,
    "original_basename": "b.txt",
    "operation": "file_copy",
    "size": 7
}

the job finished successfuly, the file does not exist in tmp directory

25 Haziran 2021 Cuma tarihinde saat 23:28:52 UTC+3 itibarıyla weiye...@gmail.com şunları yazdı:

Wei-Yen Tan

unread,
Jun 25, 2021, 5:02:36 PM6/25/21
to ansible...@googlegroups.com
That's not using the slurp module 

Sent: Saturday, June 26, 2021 8:57:56 AM

Wei-Yen Tan

unread,
Jun 25, 2021, 5:05:24 PM6/25/21
to ansible...@googlegroups.com

bulent senguler

unread,
Jun 26, 2021, 7:21:23 AM6/26/21
to Ansible Project
Thanks for your answer, it opens my sight but I still do not copy content to file on disk. I tried copy module again but it did not work. My playbook and output are below.

---
- name: cp file
  hosts: all
  tasks:
  - name: copying a file
    slurp: #win_copy:
      src: c:\test\b.txt #win_copy: #win_copy:
    register: test   #dest: /tmp  #  src: c:\test\a.txt
  - name: dosya ici
    debug:
      msg: "{{ test['content'] | b64decode }}"

  - local_action:
      module: copy
      content: "{{ test['content'] | b64decode }}"
      dest: /tmp/ba.txt


/////////// debug output  /////////////

{
    "msg": "adfasdf", // contains of my file 
    "changed": false,
    "_ansible_verbose_always": true,
    "_ansible_no_log": false
}

//////////////// local_action output //////////////////////////
{
    "changed": true,
    "uid": 998,
    "_ansible_delegated_vars": {
        "ansible_host": "localhost"
    },
    "dest": "/tmp/ba.txt",
    "owner": "awx",
    "diff": [],
    "size": 7,
    "src": "/var/lib/awx/.ansible/tmp/ansible-tmp-1624704662.69-19-50577674979617/source",
    "group": "awx",
    "_ansible_no_log": false,
    "checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
    "md5sum": "b4206b74b7563ec684336f054582605b",
    "state": "file",
    "gid": 995,
    "secontext": "system_u:object_r:tmp_t:s0",
    "mode": "0644",
    "invocation": {
        "module_args": {
            "directory_mode": null,
            "force": true,
            "remote_src": null,
            "dest": "/tmp/ba.txt",
            "selevel": null,
            "_original_basename": "tmpl88RWo",
            "delimiter": null,
            "regexp": null,
            "owner": null,
            "follow": false,
            "validate": null,
            "local_follow": null,
            "src": "/var/lib/awx/.ansible/tmp/ansible-tmp-1624704662.69-19-50577674979617/source",
            "group": null,
            "unsafe_writes": null,
            "checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
            "seuser": null,
            "serole": null,
            "content": null,
            "setype": null,
            "mode": null,
            "attributes": null,
            "backup": false
        }
    }
}

26 Haziran 2021 Cumartesi tarihinde saat 00:05:24 UTC+3 itibarıyla weiye...@gmail.com şunları yazdı:
Reply all
Reply to author
Forward
0 new messages