diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 05:17:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 05:17:02 +0000 |
commit | 514d068b7f78ac67e4dc5ba4fdef73f1f8853558 (patch) | |
tree | 9e5015ff35b09b0b55397d1819bc6d09e7890d42 /src | |
parent | Adding debian version 4.1.12-1. (diff) | |
download | python-ansible-compat-514d068b7f78ac67e4dc5ba4fdef73f1f8853558.tar.xz python-ansible-compat-514d068b7f78ac67e4dc5ba4fdef73f1f8853558.zip |
Merging upstream version 24.5.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/ansible_compat/runtime.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ansible_compat/runtime.py b/src/ansible_compat/runtime.py index 4556b7e..fbeaa98 100644 --- a/src/ansible_compat/runtime.py +++ b/src/ansible_compat/runtime.py @@ -156,6 +156,7 @@ class Runtime: # to do it multiple tilmes will cause runtime warnings from within ansible-core initialized: bool = False plugins: Plugins + _has_playbook_cache: dict[tuple[str, Path | None], bool] = {} def __init__( self, @@ -432,6 +433,28 @@ class Runtime: return False return True + def has_playbook(self, playbook: str, *, basedir: Path | None = None) -> bool: + """Return true if ansible can load a given playbook. + + This is also used for checking if playbooks from within collections + are present and if they pass syntax check. + """ + if (playbook, basedir) in self._has_playbook_cache: + return self._has_playbook_cache[playbook, basedir] + + proc = self.run(["ansible-playbook", "--syntax-check", playbook], cwd=basedir) + result = proc.returncode == 0 + if not result: + if not basedir: + basedir = Path() + msg = f"has_playbook returned false for '{basedir / playbook}' due to syntax check returning {proc.returncode}" + logging.debug(msg) + + # cache the result + self._has_playbook_cache[playbook, basedir] = result + + return result + def install_collection( self, collection: str | Path, |