Skip to content

dnf module

DnfAvailableGroups

The available (not-yet-installed) dnf groups, as DnfGroup dicts.

Commands:

dnf group list --available

Returns:

list[DnfGroup]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_available_groups.py.

DnfDisabledModules

The disabled dnf modules, as a sorted list of DnfModule dicts.

Commands:

dnf module list --disabled

Returns:

list[DnfModule]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_disabled_modules.py.

DnfEnabledModules

The enabled dnf modules, as a sorted list of DnfModule dicts.

Commands:

dnf module list --enabled

Returns:

list[DnfModule]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_enabled_modules.py.

DnfGroup

Attributes:

Name Type Description
name

The package-group name, exactly as dnf group list prints it (environment groups and regular groups alike).

DnfGroups

The installed dnf groups, as a sorted list of DnfGroup dicts.

Commands:

dnf group list --installed

Returns:

list[DnfGroup]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_groups.py.

DnfInstalledModules

The installed dnf modules, as a sorted list of DnfModule dicts.

Commands:

dnf module list --installed

Returns:

list[DnfModule]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_installed_modules.py.

DnfModule

Attributes:

Name Type Description
name

The dnf module name (an application-stream family).

stream

The module stream the row's flag applies to. For DnfDisabledModules a simulated whole-module disable carries "" -- dnf module disable names no stream, so the simulation has none to report (the real listing's rows always carry one).

DnfPackageInfo

Attributes:

Name Type Description
name

The package name, exactly as rpm -qa prints it.

versions

The package's installed versions (rpm's VERSION-RELEASE), de-duplicated and sorted -- every version groups under one name, so a multi-version package (kernel) carries all its installed versions here.

DnfPackages

The installed dnf packages, as a sorted list of DnfPackageInfo dicts.

Commands:

rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n'

Returns:

list[DnfPackageInfo]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_packages.py.

DnfRepoFile

The current content of one .repo file, or None when it is absent.

Commands:

test -e <path> && { printf '#reemote-repofile\n'; cat -- <path>; }

Returns:

str | None

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_repo.py.

DnfRepoList

The runtime dnf repositories, as a list of DnfRepoListEntry dicts.

Commands:

dnf repolist --all

Returns:

list[DnfRepoListEntry]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_repo_list.py.

DnfRepoListEntry

Attributes:

Name Type Description
repoid

The repository id (the row's first column).

name

The human-readable repository name (possibly multi-word).

status

"enabled" or "disabled" when the listing carries a status column; absent for a two-column dnf repolist.

DnfRepositories

The configured dnf repositories, as a list of DnfRepository dicts.

Commands:

for f in /etc/dnf.conf /etc/dnf.repos.d/*.repo /etc/yum.repos.d/*.repo; do [ -f "$f" ] && { printf "#reemote-filename: %s\n" "$f"; cat "$f"; }; done || true

Returns:

list[DnfRepository]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_repositories.py.

DnfRepository

Attributes:

Name Type Description
repoid

The repository id (the [section] header).

name

The human-readable repository name (the name= option, defaulting to the section id).

filename

The config/.repo file the section was read from; absent when no filename marker preceded it.

options

The section's remaining key=value options (baseurl, enabled, gpgcheck, ...) verbatim -- repo options are open-ended, so they ride in a sub-dict rather than as fixed fields (the AptSource precedent).

RpmGpgKey

Attributes:

Name Type Description
keyid

The key's short id -- the last 8 hex digits of its GPG key id, lowercased exactly as rpm stores it in the pseudo-package's VERSION.

release

The pseudo-package's RELEASE -- the hex-encoded key creation timestamp rpm recorded when the key was imported.

summary

The pseudo-package's SUMMARY -- rpm's gpg(<uid>) description of the imported key.

RpmGpgKeys

The GPG keys imported into the rpm keyring, as RpmGpgKey dicts.

Commands:

rpm -qa gpg-pubkey --queryformat '%{VERSION} %{RELEASE} %{SUMMARY}\n'

Returns:

list[RpmGpgKey]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/rpm_gpg_keys.py.

RpmPackage

The name and version of a .rpm file or an installed package.

Commands:

rpm --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' -q <package> || ! test -e <package> || rpm --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' -qp <package> 2> /dev/null

Returns:

RpmPackageInfo | None

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_rpm.py.

RpmPackageInfo

Attributes:

Name Type Description
name

The package name rpm reports for the queried name/file.

version

The package's version -- rpm's VERSION-RELEASE.

clean async

clean(
    ctx: OpContext,
    what: str = "all",
    repos: str | list[str] | tuple[str, ...] | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Remove dnf cached data, optionally scoped to repos.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
what str

The cache kind to remove: all, metadata, packages, dbcache or expire-cache. Defaults to "all".

'all'
repos str | list[str] | tuple[str, ...] | None

Repository ids to scope the removal to (--disablerepo='*' plus one --enablerepo per id). Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Defaults to None (every repo).

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The clean command, always (the operation is stateless).

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/dnf/dnf_clean.py.

key async

key(
    ctx: OpContext,
    src: IO[Any] | None = None,
    keyid: str | None = None,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Import a GPG key into, or remove one from, the target's rpm keyring.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
src IO[Any] | None

The key content as a seekable IO-like object on the control machine (an io.BytesIO/io.StringIO, a file opened with open(), ...), rewound to position 0 before it is read. Required when present=True; rejected when present=False. Defaults to None.

None
keyid str | None

The key to remove when present=False: 8 hex digits (rpm's short key id) or 16 (the long form, matched by its last 8 digits), case-insensitive. Required when present=False, ignored when present=True. Defaults to None.

None
present bool

True imports src into the rpm keyring; False removes the key keyid names from it. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The key transfer and import commands, always, when present=True (that direction is stateless); the removal command only when present=False and the key is in the rpm keyring.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/dnf/dnf_key.py.

makecache async

makecache(
    ctx: OpContext,
    repos: str | list[str] | tuple[str, ...] | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Download/refresh dnf repository metadata, optionally scoped to repos.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
repos str | list[str] | tuple[str, ...] | None

Repository ids to scope the refresh to (--disablerepo='*' plus one --enablerepo per id). Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Defaults to None (every enabled repo).

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The makecache command, always (the operation is stateless).

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_makecache.py.

module async

module(
    ctx: OpContext,
    module: str,
    stream: str | None = None,
    enabled: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Enable/disable a dnf module stream.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
module str

Name of the dnf module (an application-stream family).

required
stream str | None

The stream to enable; required when enabled=True, ignored when enabled=False. Defaults to None.

None
enabled bool

True enables module:stream; False disables the module, so every one of its streams becomes inactive. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated dnf module commands.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/dnf/dnf_module.py.

packages async

packages(
    ctx: OpContext,
    packages: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    present: bool = True,
    latest: bool = False,
    update: bool = False,
    clean: bool = False,
    nobest: bool = False,
    extra_install_args: str | None = None,
    extra_uninstall_args: str | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Install/remove/update dnf packages.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
packages str | list[str] | tuple[str, ...] | None

Packages to ensure. Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Versions can be pinned as <pkg>=<version>. Defaults to None.

None
present bool

Whether the packages should be installed. Defaults to True.

True
latest bool

Whether to upgrade installed packages without a pinned version. Defaults to False.

False
update bool

Run dnf update before installing packages. Defaults to False.

False
clean bool

Run dnf clean all before installing packages. Defaults to False.

False
nobest bool

Add the --nobest option to the install command. Defaults to False.

False
extra_install_args str | None

Additional arguments to the dnf install command. Defaults to None.

None
extra_uninstall_args str | None

Additional arguments to the dnf remove command. Defaults to None.

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated dnf package commands.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/dnf/dnf_packages.py.

repo async

repo(
    ctx: OpContext,
    src: str,
    present: bool = True,
    baseurl: str | None = None,
    description: str | None = None,
    enabled: bool = True,
    gpgcheck: bool = True,
    gpgkey: str | None = None,
    includepkgs: str | None = None,
    repo_gpgcheck: bool | None = None,
    proxy: str | None = None,
    proxy_username: str | None = None,
    proxy_password: str | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Add/remove/update a dnf repository .repo file.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
src str

The repository name; the file is /etc/yum.repos.d/<src>.repo and <src> is its [section] id.

required
present bool

Whether the .repo file should exist. Defaults to True.

True
baseurl str | None

The repository's baseurl; required when present=True. Defaults to None.

None
description str | None

The name= line. Defaults to None, using src.

None
enabled bool

Whether the repo is enabled=1 (else enabled=0). Defaults to True.

True
gpgcheck bool

Whether to set gpgcheck=1 (else gpgcheck=0) -- signature checking of the repo's packages. Defaults to True.

True
gpgkey str | None

The gpgkey= value; each whitespace-separated token must be a URL or an absolute path. Defaults to None.

None
includepkgs str | None

The includepkgs= value -- a space-separated list of package names/globs the repo may supply (e.g. datadog-agent), so it cannot provide system packages. Defaults to None (the line is omitted).

None
repo_gpgcheck bool | None

The repo_gpgcheck= value -- signature checking of the repo's metadata, distinct from gpgcheck. Defaults to None (the line is omitted, leaving dnf's own default of off).

None
proxy str | None

The proxy= value -- a proxy URL, or _none_ to disable a proxy inherited from dnf.conf. Defaults to None (the line is omitted).

None
proxy_username str | None

The proxy_username= value. Defaults to None (the line is omitted).

None
proxy_password str | None

The proxy_password= value. When set, the file is installed 0600 instead of 0644 so the password is not world-readable. Defaults to None (the line is omitted).

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated dnf repository file commands.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/dnf/dnf_repo.py.

rpm async

rpm(
    ctx: OpContext,
    src: str,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Add/remove a .rpm file package.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
src str

Path to the .rpm file on the target host.

required
present bool

Whether the package should be installed. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated dnf rpm package commands.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/dnf/dnf_rpm.py.

update async

update(
    ctx: OpContext, **kwargs: Any
) -> AsyncGenerator[Command]

Update every dnf package on the host.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The dnf update command, always (the operation is stateless).

Raises:

None

Examples:

Examples can be found in examples/modules/dnf/dnf_update.py.