dnf: Check if installroot is directory or not (#85748)

* dnf: Check if installroot is directory or not

* dnf library creates installroot if it is missing.
  check if installroot is directory or not.

Fixes: #85680

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
pull/85797/head
Abhijeet Kasurde 3 months ago committed by GitHub
parent a8dc3fae1e
commit 7b1644e0b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- dnf - Check if installroot is directory or not (https://github.com/ansible/ansible/issues/85680).

@ -537,6 +537,9 @@ class DnfModule(YumDnf):
conf.sslverify = sslverify
# Set installroot
if not os.path.isdir(installroot):
self.module.fail_json(msg=f"Installroot {installroot} must be a directory")
conf.installroot = installroot
# Load substitutions from the filesystem

@ -595,6 +595,10 @@ class Dnf5Module(YumDnf):
conf.localpkg_gpgcheck = not self.disable_gpg_check
conf.sslverify = self.sslverify
conf.clean_requirements_on_remove = self.autoremove
if not os.path.isdir(self.installroot):
self.module.fail_json(msg=f"Installroot {self.installroot} must be a directory")
conf.installroot = self.installroot
conf.use_host_config = True # needed for installroot
conf.cacheonly = "all" if self.cacheonly else "none"

@ -33,3 +33,33 @@
file:
path: "/{{ dnfroot.stdout }}/"
state: absent
- block:
- name: Clean setup
file:
path: "{{ remote_tmp_dir }}/file_root"
state: absent
- name: Setup - create invalid installroot file (not a dir)
copy:
content: ''
dest: "{{ remote_tmp_dir }}/file_root"
- name: Try with invalid installroot
dnf:
name: bash
state: present
installroot: "{{ remote_tmp_dir }}/file_root"
ignore_errors: yes
register: invalid_install_root
- name: Check if invalid installroot failed
assert:
that:
- invalid_install_root.failed
- "'Installroot ' ~ remote_tmp_dir ~ '/file_root must be a directory' in invalid_install_root.msg"
always:
- name: Cleanup invalid installroot
file:
path: "{{ remote_tmp_dir }}/file_root"
state: absent

Loading…
Cancel
Save