ansible/ansible · error · Exception
Failed to copy {src!r} to {dest!r}.
Error message
Failed to copy {src!r} to {dest!r}. What it means
Error "Failed to copy {src!r} to {dest!r}." thrown in ansible/ansible.
Source
Thrown at lib/ansible/modules/copy.py:640
b_mysrc = b_src
if remote_src and os.path.isfile(b_src):
dummy, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest))
shutil.copyfile(b_src, b_mysrc)
try:
shutil.copystat(b_src, b_mysrc)
except OSError as err:
if err.errno == errno.ENOSYS and mode == "preserve":
module.warn("Unable to copy stats {0}".format(to_native(b_src)))
else:
raise
# at this point we should always have tmp file
module.atomic_move(b_mysrc, dest, unsafe_writes=module.params['unsafe_writes'], keep_dest_attrs=not remote_src)
except OSError as ex:
raise Exception(f"Failed to copy {src!r} to {dest!r}.") from ex
changed = True
# If neither have checksums, both src and dest are directories.
checksums_none = checksum_src is None and checksum_dest is None
both_directories = os.path.isdir(module.params['src']) and (os.path.isdir(module.params['dest']) or not os.path.exists(module.params['dest']))
if checksums_none and remote_src and both_directories:
b_src = to_bytes(module.params['src'], errors='surrogate_or_strict')
b_dest = to_bytes(module.params['dest'], errors='surrogate_or_strict')
if not b_src.endswith(to_bytes(os.path.sep)):
b_basename = os.path.basename(b_src)
b_dest = os.path.join(b_dest, b_basename)
b_src = os.path.join(b_src, b'')
changed |= copy_directory(b_src, b_dest, module)
res_args = dict(
dest=dest, src=src, md5sum=md5sum_src, checksum=checksum_src, changed=changedView on GitHub (pinned to 9cf16a4aca)
Solutions
- Check permissions and free space at the destination.
- Ensure the destination directory exists or remote_src handling matches the source type.
When it happens
Trigger: Thrown at lib/ansible/modules/copy.py:640 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15).
Data as JSON: /api/errors/82e820155d1fb47a.
Report an issue: GitHub.