modules/dnf: Substitute variables in DNF cache path (#80094)

The cache directory can be specified with variables that are expanded by DNF, for example,

```
cachedir=/var/cache/yum/$basearch/$releasever
```

But the `dnf` module would use that path literally, instead of replacing
`$basearch` and `$releasever` with their values.

This commit ensures that variables in `cachedir` are properly substituted.

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
pull/83011/head
Benoît Knecht 4 weeks ago committed by GitHub
parent 46137127a2
commit d304fd86c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- dnf - Substitute variables in DNF cache path (https://github.com/ansible/ansible/pull/80094).

@ -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
#

@ -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

@ -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

Loading…
Cancel
Save