简体   繁体   中英

How to copy a file from Linux server to Windows server using Ansible playbook

I want to copy some dummy files from a Linux remote server to a Windows remote server but I'm not able to succeed. I'm using AWX but the output is throwing an error.

ERROR! 'win_copy' is not s valid attribute for a playbook 

The Ansible version I'm using is 2.9.19 and the AWX version is 21.0.0

This is the playbook I'm trying to run:

- name: testing windows files
  hosts: {{ hostname }}
  
  tasks:

- name: Copy a single file
  win_copy:
  src: /path/to/src/test.txt
  dest: user@hostname.domain.name.com:C:\Temp\renamed-test.txt

I tried with the "copy" attribute but the output is the same.

Note: I already installed the ansible.windows module but nothing changes.

Windoze is weird. Typically, Windoze has to be running WinRM.

So the first thing is to see whether you can connect at all:

- name: testing windoze connections
  hosts: all
  gather_facts: no
  tasks:  
  - name: Ping host
    win_ping:

If that works, then your win_copy will be:

  - name: Copy file
    win_copy:
      src: '/path/to/src/test.txt'
      dest: 'C:\Temp\renamed-test.txt'

The username needs to be in the variable ansible_user , and the password in ansible_password .

It looks to be syntax error. Indentation is wrong for win_copy task. The following code should at least be parsed correctly:

- name: testing windows files
  hosts: {{ hostname }}
  tasks:
    - name: Copy a single file
      win_copy:
        src: /path/to/src/test.txt
        dest: C:\Temp\renamed-test.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM