From 910d21e15c7a6dca16f95c119b12ae60b6299719 Mon Sep 17 00:00:00 2001 From: Robert Osowiecki Date: Mon, 8 Apr 2019 10:34:21 +0200 Subject: [PATCH] Allow all of yum version compare operators (#54603) * Allow all of yum version compare operators * * yum: name="foo >= VERSION" integration test * changelog fragment (cherry picked from commit 1532e31ec0bd25ff056f9d24b91e5125cfd1e155) --- changelogs/fragments/yum-select-version.yml | 3 ++ lib/ansible/module_utils/yumdnf.py | 13 +++--- test/integration/targets/yum/tasks/repo.yml | 49 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/yum-select-version.yml diff --git a/changelogs/fragments/yum-select-version.yml b/changelogs/fragments/yum-select-version.yml new file mode 100644 index 00000000000..ab56b5e273f --- /dev/null +++ b/changelogs/fragments/yum-select-version.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "yum allows comparison operators like '>=' for selecting package version" diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index 734f710c589..2fde6100f99 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -94,12 +94,13 @@ 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 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 ' - 'string of packages or a list of packages.' - ) + for name in self.names: + if ' ' in name and not any(spec in name for spec in ['@', '>', '<', '=']): + 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 ' + 'string of packages or a list of packages.' + ) # Sanity checking for autoremove if self.state is None: diff --git a/test/integration/targets/yum/tasks/repo.yml b/test/integration/targets/yum/tasks/repo.yml index 3c8fe39b4e0..643304c614c 100644 --- a/test/integration/targets/yum/tasks/repo.yml +++ b/test/integration/targets/yum/tasks/repo.yml @@ -588,3 +588,52 @@ state: absent when: ansible_pkg_mgr == 'yum' + +# https://github.com/ansible/ansible/pull/54603 +- block: + - name: Install foo < 1.1 + yum: + name: "foo < 1.1" + 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')" + + - name: Install foo >= 1.1 + yum: + name: "foo >= 1.1" + 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.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'