dnf: allow to operate on file paths (#51080)

Fixes #50843
pull/50790/head
Martin Krizek 6 years ago committed by ansibot
parent e3f8e05ecb
commit 9ec9f18b13

@ -0,0 +1,2 @@
bugfixes:
- dnf - allow to operate on file paths (https://github.com/ansible/ansible/issues/50843)

@ -747,6 +747,13 @@ class DnfModule(YumDnf):
"results": [] "results": []
} }
def _whatprovides(self, filepath):
available = self.base.sack.query().available()
pkg_spec = available.filter(provides=filepath).run()
if pkg_spec:
return pkg_spec[0].name
def _parse_spec_group_file(self): def _parse_spec_group_file(self):
pkg_specs, grp_specs, module_specs, filenames = [], [], [], [] pkg_specs, grp_specs, module_specs, filenames = [], [], [], []
already_loaded_comps = False # Only load this if necessary, it's slow already_loaded_comps = False # Only load this if necessary, it's slow
@ -758,6 +765,13 @@ class DnfModule(YumDnf):
elif name.endswith(".rpm"): elif name.endswith(".rpm"):
filenames.append(name) filenames.append(name)
elif name.startswith("@") or ('/' in name): elif name.startswith("@") or ('/' in name):
# like "dnf install /usr/bin/vi"
if '/' in name:
pkg_spec = self._whatprovides(name)
if pkg_spec:
pkg_specs.append(pkg_spec)
continue
if not already_loaded_comps: if not already_loaded_comps:
self.base.read_comps() self.base.read_comps()
already_loaded_comps = True already_loaded_comps = True

@ -664,3 +664,24 @@
state: absent state: absent
# end test case where disable_excludes is supported # end test case where disable_excludes is supported
- name: Test "dnf install /usr/bin/vi"
block:
- name: Clean vim-minimal
dnf:
name: vim-minimal
state: absent
- name: Install vim-minimal by specifying "/usr/bin/vi"
dnf:
name: /usr/bin/vi
state: present
- name: Get rpm output
command: rpm -q vim-minimal
register: rpm_output
- name: Check installation was successful
assert:
that:
- "'vim-minimal' in rpm_output.stdout"

Loading…
Cancel
Save