From 44088ef64dfefe99640a8f562e3a745d070fe833 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 30 Oct 2018 16:28:22 +0100 Subject: [PATCH] yum: fix 'package == version' syntax (#47744) (cherry picked from commit 4b8f2c99d2f2e31f1c363fdf767a07136beced69) --- .../47689-yum-fix-version-syntax.yaml | 2 ++ lib/ansible/module_utils/yumdnf.py | 2 +- test/integration/targets/yum/tasks/repo.yml | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/47689-yum-fix-version-syntax.yaml diff --git a/changelogs/fragments/47689-yum-fix-version-syntax.yaml b/changelogs/fragments/47689-yum-fix-version-syntax.yaml new file mode 100644 index 00000000000..afd7c61d7a7 --- /dev/null +++ b/changelogs/fragments/47689-yum-fix-version-syntax.yaml @@ -0,0 +1,2 @@ +bugfixes: + - yum - fix "package == version" syntax (https://github.com/ansible/ansible/pull/47744) diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index bbd693c5f95..ba3037ebcc4 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -94,7 +94,7 @@ class YumDnf(with_metaclass(ABCMeta, object)): # Fail if someone passed a space separated string # https://github.com/ansible/ansible/issues/46301 - if any((' ' in name and '@' not in name for name in self.names)): + if any((' ' in name and '@' not in name and '==' not in name for name in self.names)): module.fail_json( msg='It appears that a space separated string of packages was passed in ' 'as an argument. To operate on several packages, pass a comma separated ' diff --git a/test/integration/targets/yum/tasks/repo.yml b/test/integration/targets/yum/tasks/repo.yml index 33fdd3b43f8..3c8fe39b4e0 100644 --- a/test/integration/targets/yum/tasks/repo.yml +++ b/test/integration/targets/yum/tasks/repo.yml @@ -556,3 +556,35 @@ name: foo state: absent when: not (ansible_distribution == "Fedora" and ansible_distribution_major_version|int < 26) + +# https://github.com/ansible/ansible/issues/47689 +- block: + - name: Install foo == 1.0 + yum: + name: "foo == 1.0" + state: present + register: yum_result + + - name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + always: + - name: Clean up + yum: + name: foo + state: absent + + when: ansible_pkg_mgr == 'yum'