I'd propose to 1) transfer the files as a standalone task and 2) test the consistency of the files before using them.
- There are many options. For example, given the inventory for testing:
shell> cat hosts
[test]
test_01
test_02
test_03
[test:vars]
ansible_user=admin
ansible_become=yes
ansible_python_interpreter=/usr/local/bin/python3.8
ansible_perl_interpreter=/usr/local/bin/perl
- Simply rsync the file to the remote hosts
shell> rsync storage/bigfile.iso admin@test_01:/tmp
...
shell> cat rsync_big_file_test.bash
#!/usr/bin/bash
rhosts=$(ansible-inventory --list | jq -r '.test.hosts[]')
for host in $rhosts; do
query="._meta.hostvars.${host}.ansible_user"
ansible_user=`ansible-inventory --list | jq -r $query`
echo "Syncing storage/bigfile.iso to ${ansible_user}@${host}:/tmp ..."
rsync storage/bigfile.iso ${ansible_user}@${host}:/tmp
done
Read the inventory and iterate the synchronization in serial
shell> ./rsync_big_file_test.bash
Syncing storage/bigfile.iso to admin@test_01:/tmp ...
Syncing storage/bigfile.iso to admin@test_02:/tmp ...
Syncing storage/bigfile.iso to admin@test_03:/tmp ...
Advanced scripting in parallel is up to you.
- hosts: all
tasks:
- ansible.posix.synchronize:
src: storage/bigfile.iso
dest: /tmp
gives (abridged)
TASK [ansible.posix.synchronize] *************************************************************
changed: [test_03]
changed: [test_02]
changed: [test_01]
See Controlling playbook execution: strategies and more. By default, Ansible runs 5 forks in parallel. It's up to you to test your bandwidth and fit the number of transfers running in parallel.
- For example, get the hash
shell> sha256sum storage/bigfile.iso
15802a9db4d3e72e1a19e053bca613ca1d5236638cf66da9dabdb578dd5ac6a2 storage/bigfile.iso
The below play will test the files
shell> cat big-file-playbook.yml
- hosts: all
vars:
bigfile_iso_sha256: '15802a9db4d3e72e1a19e053bca613ca1d5236638cf66da9dabdb578dd5ac6a2'
tasks:
- stat:
path: /tmp/bigfile.iso
checksum_algorithm: sha256
register: out
- debug:
var: out.stat.checksum
- assert:
that: out.stat.checksum == bigfile_iso_sha256
fail_msg: '[ERR] Restore bigfile.iso.'
- debug:
msg: The play is running ...