Win_Copy Checksuming

Hi All

With regards to the checksuming mentioned for the win_copy module in the “force” parameter, could anyone shed some light how this works?

https://docs.ansible.com/ansible/latest/modules/win_copy_module.html#win-copy-module

The question that is going around in my mind is if I need to run win_stat with the checksum option afterwards or if win_copy is sufficient.
I’ll have some stakeholders poking holes in me what method win_copy uses, and the package that is being copied has 700 files with a size of 200mb total, so I will be glad if I can avoid win_stat.

Thank you
Lukas

Hi

The “force” parameter controls what check is used to determine whether a copy needs to occur;

  • force=no: The file on the controller is only copied when dest does not already exist.

  • force=yes (default): The file on the controller is only copied when dest does not exist, or dest has a different checksum
    The checksum part in the docs just refers to how checksums are not used to detect when a copy needs to occur. Here is an example workflow for win_copy when remote_src=no:

  1. If using content, it builds a tmp file on the controller that has the content placed in it
  2. Builds a listing of the file(s) to copy from the controller to the destination file
  3. If force=yes, this listing will include the sha1 checksum of each file to by copied across1. Sends this listing across to the Windows host. It then filters the list to include the file(s) that need to be copied across
  4. When force=no, files are only set to be copied when they don’t exist, no checksum is done here
  5. When force=yes, files are set to be copied when they don’t exist, or their checksum does not match that value in the listing sent by the controller1. The controller then checks the returned list, if there are no files to copy, it returns ‘changed=False’
  6. If only a single file needs to be copied, it is sent across as is. If multiple files need to be copied, it is compressed to a single zip which is then sent across
  7. When sending a file it is first sent to a temp directory, this is controlled with the ansible_remote_tmp variable
  8. Before copying the file a sha1 checksum of the src path is performed, this happens regardless of the force setting
  9. After copying, a sha1 checksum is calculated and compared against the src checksum. If it does not match then a failure will occur1. Once the file is copied across, the file is then copied to the correct dest path
  10. If a single file, this is just copied as is
  11. If it is multiple files (zip), the zip is expanded and copied to the proper dest paths
    As you can see there are multiple steps in the win_copy execution. The force module option just controls the idempotency checks, Ansible will still perform a checksum validation when copying the file to ensure nothing was lost during the transfer so there shouldn’t be any uncaught corruption. If you are wanting to hard code a checksum for a file with a specific checksum this would still need to be done with win_stat or stat + ‘delegate_to: localhost’ before the file is actually copied.

Unfortunately I think force is a poor name for this module option but it is there for historical and compatibility reasons with the copy module.

Thanks

Jordan

Much appreciated Jordan!

Thank you
Lukas