From d4dfa10cd25391c61bd21fa7c3e08d1ba955b52a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 7 Aug 2024 15:26:57 +0200 Subject: Merging upstream version 2.17.2. Signed-off-by: Daniel Baumann --- lib/ansible/modules/dnf.py | 28 ++++++++++++++++++++++------ lib/ansible/modules/dnf5.py | 21 +++++++++++++++++---- lib/ansible/modules/package_facts.py | 2 +- lib/ansible/modules/replace.py | 2 +- 4 files changed, 41 insertions(+), 12 deletions(-) (limited to 'lib/ansible/modules') diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index 593f006..2ab66fb 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -19,9 +19,15 @@ description: options: use_backend: description: - - By default, this module will select the backend based on the C(ansible_pkg_mgr) fact. + - Backend module to use. default: "auto" - choices: [ auto, yum, yum4, dnf4, dnf5 ] + choices: + auto: Automatically select the backend based on the C(ansible_facts.pkg_mgr) fact. + yum: Alias for V(auto) (see Notes) + dnf: M(ansible.builtin.dnf) + yum4: Alias for V(dnf) + dnf4: Alias for V(dnf) + dnf5: M(ansible.builtin.dnf5) type: str version_added: 2.15 name: @@ -287,6 +293,11 @@ notes: upstream dnf's API doesn't properly mark groups as installed, therefore upon removal the module is unable to detect that the group is installed (https://bugzilla.redhat.com/show_bug.cgi?id=1620324) + - While O(use_backend=yum) and the ability to call the action plugin as + M(ansible.builtin.yum) are provided for syntax compatibility, the YUM + backend was removed in ansible-core 2.17 because the required libraries are + not available for any supported version of Python. If you rely on this + functionality, use an older version of Ansible. requirements: - "python >= 2.6" - python-dnf @@ -723,9 +734,14 @@ class DnfModule(YumDnf): self.module.exit_json(msg="", results=results) def _is_installed(self, pkg): - return bool( - dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).installed().run() - ) + installed_query = dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).installed() + if dnf.util.is_glob_pattern(pkg): + available_query = dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).available() + return not ( + {p.name for p in available_query} - {p.name for p in installed_query} + ) + else: + return bool(installed_query) def _is_newer_version_installed(self, pkg_name): try: @@ -1336,7 +1352,7 @@ def main(): # list=repos # list=pkgspec - yumdnf_argument_spec['argument_spec']['use_backend'] = dict(default='auto', choices=['auto', 'yum', 'yum4', 'dnf4', 'dnf5']) + yumdnf_argument_spec['argument_spec']['use_backend'] = dict(default='auto', choices=['auto', 'dnf', 'yum', 'yum4', 'dnf4', 'dnf5']) module = AnsibleModule( **yumdnf_argument_spec diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 7af1f4a..3a4fdfc 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -357,10 +357,23 @@ libdnf5 = None def is_installed(base, spec): settings = libdnf5.base.ResolveSpecSettings() - query = libdnf5.rpm.PackageQuery(base) - query.filter_installed() - match, nevra = query.resolve_pkg_spec(spec, settings, True) - return match + installed_query = libdnf5.rpm.PackageQuery(base) + installed_query.filter_installed() + match, nevra = installed_query.resolve_pkg_spec(spec, settings, True) + + # FIXME use `is_glob_pattern` function when available: + # https://github.com/rpm-software-management/dnf5/issues/1563 + glob_patterns = set("*[?") + if any(set(char) & glob_patterns for char in spec): + available_query = libdnf5.rpm.PackageQuery(base) + available_query.filter_available() + available_query.resolve_pkg_spec(spec, settings, True) + + return not ( + {p.get_name() for p in available_query} - {p.get_name() for p in installed_query} + ) + else: + return match def is_newer_version_installed(base, spec): diff --git a/lib/ansible/modules/package_facts.py b/lib/ansible/modules/package_facts.py index 11a8f61..dd9badf 100644 --- a/lib/ansible/modules/package_facts.py +++ b/lib/ansible/modules/package_facts.py @@ -440,7 +440,7 @@ class APK(CLIMgr): def list_installed(self): rc, out, err = module.run_command([self._cli, 'info', '-v']) - if rc != 0 or err: + if rc != 0: raise Exception("Unable to list packages rc=%s : %s" % (rc, err)) return out.splitlines() diff --git a/lib/ansible/modules/replace.py b/lib/ansible/modules/replace.py index 2fee290..8e4b976 100644 --- a/lib/ansible/modules/replace.py +++ b/lib/ansible/modules/replace.py @@ -140,7 +140,7 @@ EXAMPLES = r''' ansible.builtin.replace: path: /etc/hosts after: '(?m)^' - before: '(?m)^' + before: '' regexp: '^(.+)$' replace: '# \1' -- cgit v1.2.3