Ansible win_copy error "Unhandled exception while executing module: Access to the path 'D:\System Volume Information' is denied"

Issue description

While copying files and folders from a source path to a destination path using Ansible win_copy module we might notice an error Access to the path 'D:\System Volume Information' is denied

Below is an example playbook to copy files and folders from a shared path to a remote windows server D:\ drive.

---
- name: Copy files
  win_copy:
   src: '\\webserver\corp\D'
   dest: 'D:\'
   

Root cause

The folder System Volume Information is a hidden folder that contains OS-related information. Windows will not allow you to access this folder and it is not advisable to delete it.

In order to view it, firstly you have to navigate to the Drive location, select View and check the Hidden items . Then, select view -> Options -> change folder and search options -> View, uncheck Hide protected operating system files.

Using this method you can confirm where the folder is present. Even though we are providing the destination location as D:\ and not mentioning System Volume Information this issue occurs, because we are trying to copy many files to a root disk location.

The win_copy module copies the files and then tries to find the size of the destination location. During this task, win_copy module internally tries to checks the size of System Volume Information  folder which fails due to access reistrictions.

Resolution

Method 1 :

Copy the files to another location inside D:\ instead of specifying the D:\ directly.

---
- name: Copy files
  win_copy:
   src: '\\webserver\corp\D'
   dest: 'D:\Folder\'

Method 2:

Copy each of the folders in the shared drive separately using a loop so that all files are not copied together.

---
- name: Copy files
  win_copy:
   src: '{{item}}'
   dest: 'D:\'
  loop: "{{paths}}" 
paths:
 -  '\\webserver\corp\D\folder1'
 -  '\\webserver\corp\D\folder2'
 

Method 3:

Use powershell command xcopy or Copy-Item with win_shell module.

---
- name: Copy files
  win_shell: '\\webserver\corp\D\' 'D:\' /y /s /h
Vipin

Vipin

I am a dreamer. I admire the web. I admire anything about the web.