{"record":{"id":"82e820155d1fb47a","repo":"ansible/ansible","slug":"failed-to-copy-src-r-to-dest-r","errorCode":null,"errorMessage":"Failed to copy {src!r} to {dest!r}.","messagePattern":"Failed to copy (.+?) to (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"lib/ansible/modules/copy.py","lineNumber":640,"sourceCode":"                b_mysrc = b_src\n                if remote_src and os.path.isfile(b_src):\n\n                    dummy, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest))\n\n                    shutil.copyfile(b_src, b_mysrc)\n                    try:\n                        shutil.copystat(b_src, b_mysrc)\n                    except OSError as err:\n                        if err.errno == errno.ENOSYS and mode == \"preserve\":\n                            module.warn(\"Unable to copy stats {0}\".format(to_native(b_src)))\n                        else:\n                            raise\n\n                # at this point we should always have tmp file\n                module.atomic_move(b_mysrc, dest, unsafe_writes=module.params['unsafe_writes'], keep_dest_attrs=not remote_src)\n\n            except OSError as ex:\n                raise Exception(f\"Failed to copy {src!r} to {dest!r}.\") from ex\n        changed = True\n\n    # If neither have checksums, both src and dest are directories.\n    checksums_none = checksum_src is None and checksum_dest is None\n    both_directories = os.path.isdir(module.params['src']) and (os.path.isdir(module.params['dest']) or not os.path.exists(module.params['dest']))\n    if checksums_none and remote_src and both_directories:\n        b_src = to_bytes(module.params['src'], errors='surrogate_or_strict')\n        b_dest = to_bytes(module.params['dest'], errors='surrogate_or_strict')\n\n        if not b_src.endswith(to_bytes(os.path.sep)):\n            b_basename = os.path.basename(b_src)\n            b_dest = os.path.join(b_dest, b_basename)\n            b_src = os.path.join(b_src, b'')\n\n        changed |= copy_directory(b_src, b_dest, module)\n\n    res_args = dict(\n        dest=dest, src=src, md5sum=md5sum_src, checksum=checksum_src, changed=changed","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/ansible/ansible/blob/9cf16a4aca7898481c257f1e17ad28d0b67b1f85/lib/ansible/modules/copy.py#L622-L658","documentation":"Error \"Failed to copy {src!r} to {dest!r}.\" thrown in ansible/ansible.","triggerScenarios":"Thrown at lib/ansible/modules/copy.py:640 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check permissions and free space at the destination.","Ensure the destination directory exists or remote_src handling matches the source type."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9cf16a4aca7898481c257f1e17ad28d0b67b1f85","analyzedAt":"2026-08-15T00:15:47.100Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}