diff --git a/changelogs/fragments/dnf_cache_path.yml b/changelogs/fragments/dnf_cache_path.yml new file mode 100644 index 00000000000..50b72f9a109 --- /dev/null +++ b/changelogs/fragments/dnf_cache_path.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - dnf - Substitute variables in DNF cache path (https://github.com/ansible/ansible/pull/80094). diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index fb9fa6ae5d2..16b3bcc2b41 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -403,6 +403,7 @@ from ansible.module_utils.yumdnf import YumDnf, yumdnf_argument_spec # to set proper locale before importing dnf to be able to scrape # the output in some cases (FIXME?). dnf = None +libdnf = None class DnfModule(YumDnf): @@ -483,6 +484,7 @@ class DnfModule(YumDnf): os.environ['LANGUAGE'] = os.environ['LANG'] = locale global dnf + global libdnf try: import dnf import dnf.const @@ -490,6 +492,7 @@ class DnfModule(YumDnf): import dnf.package import dnf.subject import dnf.util + import libdnf HAS_DNF = True except ImportError: HAS_DNF = False @@ -557,6 +560,9 @@ class DnfModule(YumDnf): # Load substitutions from the filesystem conf.substitutions.update_from_etc(installroot) + # Substitute variables in cachedir path + conf.cachedir = libdnf.conf.ConfigParser.substitute(conf.cachedir, conf.substitutions) + # Handle different DNF versions immutable mutable datatypes and # dnf v1/v2/v3 # diff --git a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini index 0251f674b51..0a8a3e6b40f 100644 --- a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini +++ b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini @@ -58,6 +58,9 @@ ignore_missing_imports = True [mypy-dnf.*] ignore_missing_imports = True +[mypy-libdnf.*] +ignore_missing_imports = True + [mypy-apt.*] ignore_missing_imports = True diff --git a/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini b/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini index b4e7b05eb9f..ddabecdabb6 100644 --- a/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini +++ b/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini @@ -25,6 +25,9 @@ ignore_missing_imports = True [mypy-dnf.*] ignore_missing_imports = True +[mypy-libdnf.*] +ignore_missing_imports = True + [mypy-apt.*] ignore_missing_imports = True