From 72f1ad67f5e6d9906d013445f99350e9b82b942a Mon Sep 17 00:00:00 2001 From: Vyacheslav Rakhinskiy Date: Fri, 9 Feb 2024 02:20:35 +0300 Subject: [PATCH 1/2] Skip symlink creation if exist or remove it before create --- src/molecule/provisioner/ansible.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index 3a4e85261..49eb3968b 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -904,6 +904,14 @@ def _link_or_update_vars(self): if not os.path.exists(source): msg = f"The source path '{source}' does not exist." util.sysexit_with_message(msg) + if os.path.exists(target): + if os.path.realpath(target) == os.path.realpath(source): + msg=f"Required symlink {target} to {source} exist, skip creation" + LOG.debug(msg) + continue + msg=f"Required symlink {target} exist with another source" + LOG.debug(msg) + os.remove(target) msg = f"Inventory {source} linked to {target}" LOG.debug(msg) os.symlink(source, target) From 4b1acaaa3d812eae7c65a10cae58351da28492a0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 23:54:15 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/molecule/provisioner/ansible.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index 49eb3968b..92f1abb54 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -906,10 +906,10 @@ def _link_or_update_vars(self): util.sysexit_with_message(msg) if os.path.exists(target): if os.path.realpath(target) == os.path.realpath(source): - msg=f"Required symlink {target} to {source} exist, skip creation" + msg = f"Required symlink {target} to {source} exist, skip creation" LOG.debug(msg) continue - msg=f"Required symlink {target} exist with another source" + msg = f"Required symlink {target} exist with another source" LOG.debug(msg) os.remove(target) msg = f"Inventory {source} linked to {target}"