AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible win_copy Module: Copy Files to Windows Hosts (ansible.windows.win_copy) — Video Tutorial
How to copy files to Windows remote hosts with Ansible win_copy module (ansible.windows.win_copy). Transfer files, directories, set permissions. Practical YAML playbook examples.
What You'll Learn
- How to copy files to Windows remote hosts?
- Ansible copy files to Windows remote hosts
- Parameters
- Demo
- Conclusion
- Copy File to Windows
- Copy Directory
- Copy Content (Inline)
- Copy with Backup
- Remote to Remote Copy
Full Tutorial Content
How to copy files to Windows remote hosts?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot
Ansible copy files to Windows remote hosts
Today we’re talking about Ansible module `win_copy`.
The full name is `ansible.windows.win_copy` which means is part of the collection of modules “`ansible.windows`” targeted windows remote hosts.
This module is pretty stable and out for years.
The purpose is to copy files from the local machine to remote locations.
Because win_copy runs over WinRM, it is not a very efficient transfer mechanism. If you plan to send large files consider hosting them on a web service and using `ansible.windows.win_get_url` instead.
Please note that the opposite is done by module win_fetch.
On Linux target use the module `ansible.builtin.copy`.
Please note that the opposite is done by module `win_fetch`.
On Linux target use the [Ansible copy module](/articles/copy-files-to-remote-hosts-ansible-module-copy)..
Parameters
- `dest` _path_ - remote path
- `src` _string_ - local path
- `backup` _boolean_ - no / yes
- `force` _string_ - yes / no
I'm going to summarize the most useful parameters.
The only required parameter is "dest" which specifies the remote absolute path destination. It's better with "\", the Windows way, instead of "/", the Unix way. Please also verify that the remote user has the right to write in this path.
The "src" specifies the source file in the controller host. It could be a relative or absolute path. I recommend absolutely. If the source is a directory all the content is copied.
Please be more careful with the "/" at the end. If present only the content of the directory is copied, if you want the directory and the content you need to omit the "/" character.
The "backup" boolean parameter allows you to create a backup if the utility overwrites any file.
The default behavior is to transfer the file only if not present or differ in the target host, the file is also verified by Ansible with a checksum on the source and target host automatically. If you want to transfer the all the time the file you need to toggle the "force" parameter to "no". Please note that setting to "no" also disables the checksum that could speed up the process but also corrupt the file.
Demo
Let's jump in a real-life playbook to copy files to Windows remote hosts with Ansible.
- copy.yml
```yaml
---
- name: win_copy module Playbook
hosts: all
become: false
gather_facts: false
vars:
source: "report.txt"
destination: "Desktop/report.txt"
tasks:
- name: copy report.txt
ansible.windows.win_copy:
src: "{{ source }}"
dest: "{{ destination }}"
```
- report.txt
```txt
test report.txt
```
[code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/copy%20files%20to%20remote%20hosts)
Conclusion
Now you know how to copy files to remote Windows hosts with Ansible.
Copy File to Windows
```yaml
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 6 min
- Category: installation
Read the full written article: Ansible win_copy Module: Copy Files to Windows Hosts (ansible.windows.win_copy)
Related Video Tutorials
- Ansible win_stat: Check if File or Directory Exists on Windows (Examples) — How to check if a file or directory exists on Windows using Ansible win_stat module. Conditional tasks, file properties, checksum verification with practical examples.
- Ansible Copy Multiple Files: fileglob Lookup & with_fileglob Examples — Discover how to use Ansible fileglob lookup plugin and copy module to efficiently transfer multiple files to remote hosts. Explore practical examples and steps.
- Ansible fetch Module: Copy Files from Remote Hosts to Control Node — How to copy files from remote hosts with Ansible fetch module (ansible.builtin.fetch). Download logs, configs, backups from Linux and Windows. Practical YAML playbook examples.
- Ansible copy Module: Copy Files to Remote Hosts (ansible.builtin.copy Guide) — How to copy files to remote hosts with Ansible copy module (ansible.builtin.copy). Transfer files, set permissions, use content parameter, backup. Practical YAML playbook examples.
- Ansible Create File with Content: copy Module content Parameter — How to create files with content in Ansible using the copy module content parameter. Write text, YAML, JSON to files without templates. Practical YAML playbook examples.
- Ansible win_file Module: Create & Manage Files on Windows (Guide) — How to create and manage files on Windows with Ansible win_file module (ansible.windows.win_file). Create files, directories, symlinks on Windows. Practical YAML playbook examples.