dnf: Add nobest option (#70318)

* dnf: Add nobest option

* dnf: Fix indent, add nobest specifically to dnf not yum

* Add changelog for dnf: add nobest option

* dnf: Add nobest to yumdnf module argument_spec

* dnf: remove nobest from module paramaters in yumdnf.py

* dnf: Add test for nobest option

* dnf: Cleanup packages in nobest test at last

* dnf: Cleanup manually added repos in nobest test at last

* dnf: Remove dnf-plugins-core as well in nobest test

* dnf: Change nobest release version to 2.11

* Change changelog number according to change in PR number

* Change changelog number according to change in PR number
This commit is contained in:
Amin Vakil 2020-07-27 14:32:07 +04:30 committed by GitHub
parent 205eda335f
commit 9d2982549d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- dnf - Add nobest option (https://github.com/ansible/ansible/issues/69983)

View file

@ -200,6 +200,13 @@ options:
type: bool
default: "no"
version_added: "2.10"
nobest:
description:
- Set best option to False, so that transactions are not limited to best candidates only.
required: false
type: bool
default: "no"
version_added: "2.11"
notes:
- When used with a `loop:` each package will be processed individually, it is much more efficient to pass the list directly to the `name` option.
- Group removal doesn't work if the group was installed with Ansible because
@ -331,6 +338,7 @@ class DnfModule(YumDnf):
# DNF specific args that are not part of YumDnf
self.allowerasing = self.module.params['allowerasing']
self.nobest = self.module.params['nobest']
def is_lockfile_pid_valid(self):
# FIXME? it looks like DNF takes care of invalid lock files itself?
@ -574,6 +582,10 @@ class DnfModule(YumDnf):
if self.skip_broken:
conf.strict = 0
# Set best
if self.nobest:
conf.best = 0
if self.download_only:
conf.downloadonly = True
if self.download_dir:
@ -1273,6 +1285,7 @@ def main():
# Extend yumdnf_argument_spec with dnf-specific features that will never be
# backported to yum because yum is now in "maintenance mode" upstream
yumdnf_argument_spec['argument_spec']['allowerasing'] = dict(default=False, type='bool')
yumdnf_argument_spec['argument_spec']['nobest'] = dict(default=False, type='bool')
module = AnsibleModule(
**yumdnf_argument_spec

View file

@ -44,3 +44,7 @@
- include_tasks: logging.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('31', '>=')) or
(ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>='))
- include_tasks: nobest.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('24', '>=') and ansible_distribution_major_version is version('31', '<=')) or
(ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>='))

View file

@ -0,0 +1,34 @@
- name: Install dnf-plugins-core in order to use dnf config-manager
dnf:
name: dnf-plugins-core
state: present
- name: Add docker-ce repo (Only RedHat & CentOS)
shell: dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
when: (ansible_distribution in ['RedHat', 'CentOS'])
- name: Add docker-ce repo (Only Fedora)
shell: dnf config-manager --add-repo=https://download.docker.com/linux/fedora/docker-ce.repo
when: (ansible_distribution in ['Fedora'])
- name: Install docker using nobest option
dnf:
name: docker-ce
state: present
nobest: true
register: dnf_result
- name: Verify installation of docker-ce
assert:
that:
- not dnf_result is failed
- name: Cleanup packages
dnf:
name: docker-ce, dnf-plugins-core
state: absent
- name: Cleanup manually added repos
file:
name: "/etc/yum.repos.d/docker-ce.repo"
state: absent