From 9d2982549d5af1e64b8df20f7a60adae5f351a4a Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Mon, 27 Jul 2020 14:32:07 +0430 Subject: [PATCH] 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 --- .../fragments/70318-dnf-add-nobest-option.yml | 3 ++ lib/ansible/modules/dnf.py | 13 +++++++ test/integration/targets/dnf/tasks/main.yml | 4 +++ test/integration/targets/dnf/tasks/nobest.yml | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 changelogs/fragments/70318-dnf-add-nobest-option.yml create mode 100644 test/integration/targets/dnf/tasks/nobest.yml diff --git a/changelogs/fragments/70318-dnf-add-nobest-option.yml b/changelogs/fragments/70318-dnf-add-nobest-option.yml new file mode 100644 index 00000000000..c841f06b127 --- /dev/null +++ b/changelogs/fragments/70318-dnf-add-nobest-option.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - dnf - Add nobest option (https://github.com/ansible/ansible/issues/69983) diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index ab49528766e..67f3f28e548 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -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 diff --git a/test/integration/targets/dnf/tasks/main.yml b/test/integration/targets/dnf/tasks/main.yml index 05881184039..891c0c72359 100644 --- a/test/integration/targets/dnf/tasks/main.yml +++ b/test/integration/targets/dnf/tasks/main.yml @@ -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', '>=')) diff --git a/test/integration/targets/dnf/tasks/nobest.yml b/test/integration/targets/dnf/tasks/nobest.yml new file mode 100644 index 00000000000..38f0e3732b0 --- /dev/null +++ b/test/integration/targets/dnf/tasks/nobest.yml @@ -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