From 853755490b4ee69a7c51b3df39b89328b5256730 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:50:57 -0500 Subject: [PATCH] make the condition more restrictive, to ensure the destination is a directory (or doesn't exist, so it can be created) --- lib/ansible/modules/copy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/copy.py b/lib/ansible/modules/copy.py index bf2cf1bca90..fc904ae2768 100644 --- a/lib/ansible/modules/copy.py +++ b/lib/ansible/modules/copy.py @@ -642,7 +642,9 @@ def main(): changed = True # If neither have checksums, both src and dest are directories. - if checksum_src is None and checksum_dest is None and remote_src and os.path.isdir(module.params['src']): + 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')