From 3d1ca5638be09cecb72e6784667f8e5cbf670a24 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 26 Nov 2021 20:53:58 +0100 Subject: [PATCH] python_requirements_info - fail when version operator used without version (#3785) (#3793) * python_requirements_info - fail when version operator used without version * added changelog fragment * simplified way of achieving the same result (cherry picked from commit 59c1859fb3cd4e5d3f2955e83b16de4ea3894156) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- ...3785-python_requirements_info-versionless-op.yaml | 2 ++ plugins/modules/system/python_requirements_info.py | 4 ++-- .../targets/python_requirements_info/tasks/main.yml | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3785-python_requirements_info-versionless-op.yaml diff --git a/changelogs/fragments/3785-python_requirements_info-versionless-op.yaml b/changelogs/fragments/3785-python_requirements_info-versionless-op.yaml new file mode 100644 index 0000000000..8ae420d0c8 --- /dev/null +++ b/changelogs/fragments/3785-python_requirements_info-versionless-op.yaml @@ -0,0 +1,2 @@ +bugfixes: + - python_requirements_info - fails if version operator used without version (https://github.com/ansible-collections/community.general/pull/3785). diff --git a/plugins/modules/system/python_requirements_info.py b/plugins/modules/system/python_requirements_info.py index 081826f4e6..c05eb097d0 100644 --- a/plugins/modules/system/python_requirements_info.py +++ b/plugins/modules/system/python_requirements_info.py @@ -121,7 +121,7 @@ def main(): python_version=sys.version, python_system_path=sys.path, ) - pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(==|[><]=?)?([0-9.]+)?$') + pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(?:(==|[><]=?)([0-9.]+))?$') results = dict( not_found=[], @@ -131,7 +131,7 @@ def main(): for dep in (module.params.get('dependencies') or []): match = pkg_dep_re.match(dep) - if match is None: + if not match: module.fail_json(msg="Failed to parse version requirement '{0}'. Must be formatted like 'ansible>2.6'".format(dep)) pkg, op, version = match.groups() if op is not None and op not in operations: diff --git a/tests/integration/targets/python_requirements_info/tasks/main.yml b/tests/integration/targets/python_requirements_info/tasks/main.yml index 9dc2ae44dc..4a1639d230 100644 --- a/tests/integration/targets/python_requirements_info/tasks/main.yml +++ b/tests/integration/targets/python_requirements_info/tasks/main.yml @@ -25,3 +25,15 @@ that: - "'installed' in dep_info.valid.pip" - "'notreal' in dep_info.not_found" + +- name: wrong specs + python_requirements_info: + dependencies: + - ansible< + register: wrong_spec1 + ignore_errors: true + +- name: ensure wrong specs return error + assert: + that: + - wrong_spec1 is failed