diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 558455fdbf1..6a722712475 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -130,7 +130,7 @@ options: - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin) - - Requires python3-libdnf5 5.2.0.0+ + - Requires python3-libdnf5 5.2.0.0+. type: list elements: str default: [] @@ -139,7 +139,7 @@ options: - I(Plugin) name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin). - - Requires python3-libdnf5 5.2.0.0+ + - Requires python3-libdnf5 5.2.0.0+. type: list default: [] elements: str @@ -436,6 +436,21 @@ class Dnf5Module(YumDnf): self.pkg_mgr_name = "dnf5" + def fail_on_non_existing_plugins(self, base): + # https://github.com/rpm-software-management/dnf5/issues/1460 + plugin_names = [p.get_name() for p in base.get_plugins_info()] + msg = [] + if enable_unmatched := set(self.enable_plugin).difference(plugin_names): + msg.append( + f"No matches were found for the following plugin name patterns while enabling libdnf5 plugins: {", ".join(enable_unmatched)}." + ) + if disable_unmatched := set(self.disable_plugin).difference(plugin_names): + msg.append( + f"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: {", ".join(disable_unmatched)}." + ) + if msg: + self.module.fail_json(msg=" ".join(msg)) + def _ensure_dnf(self): locale = get_best_parsable_locale(self.module) os.environ["LC_ALL"] = os.environ["LC_MESSAGES"] = locale @@ -540,6 +555,9 @@ class Dnf5Module(YumDnf): base.setup() + # https://github.com/rpm-software-management/dnf5/issues/1460 + self.fail_on_non_existing_plugins(base) + log_router = base.get_logger() global_logger = libdnf5.logger.GlobalLogger() global_logger.set(log_router.get(), libdnf5.logger.Logger.Level_DEBUG)