From 1d3d6a3e2d2c4b7e50ebc0f191430bfbef4fd40a Mon Sep 17 00:00:00 2001 From: feran Date: Mon, 3 Dec 2018 21:57:25 +0800 Subject: [PATCH] archive: Fix check if archive is created in path to be removed (#29420) --- lib/ansible/modules/files/archive.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/files/archive.py b/lib/ansible/modules/files/archive.py index 31f6769ba7..9db864f80d 100644 --- a/lib/ansible/modules/files/archive.py +++ b/lib/ansible/modules/files/archive.py @@ -261,8 +261,13 @@ def main(): arcroot += os.sep # Don't allow archives to be created anywhere within paths to be removed - if remove and os.path.isdir(path) and dest.startswith(path): - module.fail_json(path=', '.join(paths), msg='Error, created archive can not be contained in source paths when remove=True') + if remove and os.path.isdir(path): + path_dir = path + if path[-1] != '/': + path_dir += '/' + + if dest.startswith(path_dir): + module.fail_json(path=', '.join(paths), msg='Error, created archive can not be contained in source paths when remove=True') if os.path.lexists(path) and path not in expanded_exclude_paths: archive_paths.append(path)