From 378cc9668c38535e522dc82d7afe734c3d6158fe Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 30 Nov 2018 12:00:33 -0600 Subject: [PATCH] dnf module load/init dnf pkg mgr plugins properly (#49278) * dnf module load/init dnf pkg mgr plugins properly Fixes #45940 Signed-off-by: Adam Miller --- .../fragments/dnf-fix-plugin-loading.yaml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/dnf-fix-plugin-loading.yaml diff --git a/changelogs/fragments/dnf-fix-plugin-loading.yaml b/changelogs/fragments/dnf-fix-plugin-loading.yaml new file mode 100644 index 0000000000..ceb4fc17db --- /dev/null +++ b/changelogs/fragments/dnf-fix-plugin-loading.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "dnf module properly load and initialize dnf package manager plugins" diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 48087b67f0..d8c2e14787 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -495,15 +495,11 @@ class DnfModule(YumDnf): def _configure_base(self, base, conf_file, disable_gpg_check, installroot='/'): """Configure the dnf Base object.""" - if self.enable_plugin and self.disable_plugin: - base.init_plugins(self.disable_plugin, self.enable_plugin) - elif self.enable_plugin: - base.init_plugins(enable_plugins=self.enable_plugin) - elif self.disable_plugin: - base.init_plugins(self.disable_plugin) - conf = base.conf + # Read the configuration file + conf.read() + # Turn off debug messages in the output conf.debuglevel = 0 @@ -563,9 +559,6 @@ class DnfModule(YumDnf): # Default in dnf upstream is true conf.clean_requirements_on_remove = self.autoremove - # Read the configuration file - conf.read() - def _specify_repositories(self, base, disablerepo, enablerepo): """Enable and disable repositories matching the provided patterns.""" base.read_all_repos() @@ -588,6 +581,12 @@ class DnfModule(YumDnf): base = dnf.Base() self._configure_base(base, conf_file, disable_gpg_check, installroot) self._specify_repositories(base, disablerepo, enablerepo) + try: + base.init_plugins(set(self.disable_plugin), set(self.enable_plugin)) + base.pre_configure_plugins() + base.configure_plugins() + except AttributeError: + pass # older versions of dnf didn't require this and don't have these methods try: base.fill_sack(load_system_repo='auto') except dnf.exceptions.RepoError as e: