Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all of yum version compare operators #54603

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/yum-select-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "yum allows comparison operators like '>=' for selecting package version"
13 changes: 7 additions & 6 deletions lib/ansible/module_utils/yumdnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ def __init__(self, module):

# 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:
Expand Down
50 changes: 50 additions & 0 deletions test/integration/targets/yum/tasks/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,56 @@

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'

# https://github.com/ansible/ansible/issues/45250
- block:
- name: Install foo-1.0, foo-bar-1.0, bar-1.0
Expand Down