summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/dnf.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/dnf.py')
-rw-r--r--lib/ansible/modules/dnf.py71
1 files changed, 43 insertions, 28 deletions
diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py
index 8131833e..7f5afc39 100644
--- a/lib/ansible/modules/dnf.py
+++ b/lib/ansible/modules/dnf.py
@@ -18,33 +18,40 @@ short_description: Manages packages with the I(dnf) package manager
description:
- Installs, upgrade, removes, and lists packages and groups with the I(dnf) package manager.
options:
+ use_backend:
+ description:
+ - By default, this module will select the backend based on the C(ansible_pkg_mgr) fact.
+ default: "auto"
+ choices: [ auto, dnf4, dnf5 ]
+ type: str
+ version_added: 2.15
name:
description:
- "A package name or package specifier with version, like C(name-1.0).
When using state=latest, this can be '*' which means run: dnf -y update.
- You can also pass a url or a local path to a rpm file.
+ You can also pass a url or a local path to an rpm file.
To operate on several packages this can accept a comma separated string of packages or a list of packages."
- Comparison operators for package version are valid here C(>), C(<), C(>=), C(<=). Example - C(name >= 1.0).
Spaces around the operator are required.
- You can also pass an absolute path for a binary which is provided by the package to install.
See examples for more information.
- required: true
aliases:
- pkg
type: list
elements: str
+ default: []
list:
description:
- Various (non-idempotent) commands for usage with C(/usr/bin/ansible) and I(not) playbooks.
- Use M(ansible.builtin.package_facts) instead of the C(list) argument as a best practice.
+ Use M(ansible.builtin.package_facts) instead of the O(list) argument as a best practice.
type: str
state:
description:
- - Whether to install (C(present), C(latest)), or remove (C(absent)) a package.
- - Default is C(None), however in effect the default action is C(present) unless the C(autoremove) option is
- enabled for this module, then C(absent) is inferred.
+ - Whether to install (V(present), V(latest)), or remove (V(absent)) a package.
+ - Default is V(None), however in effect the default action is V(present) unless the O(autoremove) option is
+ enabled for this module, then V(absent) is inferred.
choices: ['absent', 'present', 'installed', 'removed', 'latest']
type: str
@@ -55,6 +62,7 @@ options:
When specifying multiple repos, separate them with a ",".
type: list
elements: str
+ default: []
disablerepo:
description:
@@ -63,6 +71,7 @@ options:
When specifying multiple repos, separate them with a ",".
type: list
elements: str
+ default: []
conf_file:
description:
@@ -72,7 +81,7 @@ options:
disable_gpg_check:
description:
- Whether to disable the GPG checking of signatures of packages being
- installed. Has an effect only if state is I(present) or I(latest).
+ installed. Has an effect only if O(state) is V(present) or V(latest).
- This setting affects packages installed from a repository as well as
"local" packages installed from the filesystem or a URL.
type: bool
@@ -95,9 +104,9 @@ options:
autoremove:
description:
- - If C(true), removes all "leaf" packages from the system that were originally
+ - If V(true), removes all "leaf" packages from the system that were originally
installed as dependencies of user-installed packages but which are no longer
- required by any such package. Should be used alone or when state is I(absent)
+ required by any such package. Should be used alone or when O(state) is V(absent)
type: bool
default: "no"
version_added: "2.4"
@@ -108,6 +117,7 @@ options:
version_added: "2.7"
type: list
elements: str
+ default: []
skip_broken:
description:
- Skip all unavailable packages or packages with broken dependencies
@@ -118,7 +128,7 @@ options:
update_cache:
description:
- Force dnf to check if cache is out of date and redownload if needed.
- Has an effect only if state is I(present) or I(latest).
+ Has an effect only if O(state) is V(present) or V(latest).
type: bool
default: "no"
aliases: [ expire-cache ]
@@ -126,20 +136,20 @@ options:
update_only:
description:
- When using latest, only update installed packages. Do not install packages.
- - Has an effect only if state is I(latest)
+ - Has an effect only if O(state) is V(latest)
default: "no"
type: bool
version_added: "2.7"
security:
description:
- - If set to C(true), and C(state=latest) then only installs updates that have been marked security related.
+ - If set to V(true), and O(state=latest) then only installs updates that have been marked security related.
- Note that, similar to C(dnf upgrade-minimal), this filter applies to dependencies as well.
type: bool
default: "no"
version_added: "2.7"
bugfix:
description:
- - If set to C(true), and C(state=latest) then only installs updates that have been marked bugfix related.
+ - If set to V(true), and O(state=latest) then only installs updates that have been marked bugfix related.
- Note that, similar to C(dnf upgrade-minimal), this filter applies to dependencies as well.
default: "no"
type: bool
@@ -151,32 +161,34 @@ options:
version_added: "2.7"
type: list
elements: str
+ default: []
disable_plugin:
description:
- I(Plugin) name to disable for the install/update operation.
The disabled plugins will not persist beyond the transaction.
version_added: "2.7"
type: list
+ default: []
elements: str
disable_excludes:
description:
- Disable the excludes defined in DNF config files.
- - If set to C(all), disables all excludes.
- - If set to C(main), disable excludes defined in [main] in dnf.conf.
- - If set to C(repoid), disable excludes defined for given repo id.
+ - If set to V(all), disables all excludes.
+ - If set to V(main), disable excludes defined in [main] in dnf.conf.
+ - If set to V(repoid), disable excludes defined for given repo id.
version_added: "2.7"
type: str
validate_certs:
description:
- - This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to C(false), the SSL certificates will not be validated.
- - This should only set to C(false) used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
+ - This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to V(false), the SSL certificates will not be validated.
+ - This should only set to V(false) used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
type: bool
default: "yes"
version_added: "2.7"
sslverify:
description:
- Disables SSL validation of the repository server for this transaction.
- - This should be set to C(false) if one of the configured repositories is using an untrusted or self-signed certificate.
+ - This should be set to V(false) if one of the configured repositories is using an untrusted or self-signed certificate.
type: bool
default: "yes"
version_added: "2.13"
@@ -196,7 +208,7 @@ options:
install_repoquery:
description:
- This is effectively a no-op in DNF as it is not needed with DNF, but is an accepted parameter for feature
- parity/compatibility with the I(yum) module.
+ parity/compatibility with the M(ansible.builtin.yum) module.
type: bool
default: "yes"
version_added: "2.7"
@@ -222,12 +234,12 @@ options:
download_dir:
description:
- Specifies an alternate directory to store packages.
- - Has an effect only if I(download_only) is specified.
+ - Has an effect only if O(download_only) is specified.
type: str
version_added: "2.8"
allowerasing:
description:
- - If C(true) it allows erasing of installed packages to resolve dependencies.
+ - If V(true) it allows erasing of installed packages to resolve dependencies.
required: false
type: bool
default: "no"
@@ -371,9 +383,8 @@ import os
import re
import sys
-from ansible.module_utils._text import to_native, to_text
+from ansible.module_utils.common.text.converters import to_native, to_text
from ansible.module_utils.urls import fetch_file
-from ansible.module_utils.six import PY2, text_type
from ansible.module_utils.compat.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule
@@ -570,6 +581,7 @@ class DnfModule(YumDnf):
import dnf.cli
import dnf.const
import dnf.exceptions
+ import dnf.package
import dnf.subject
import dnf.util
HAS_DNF = True
@@ -954,12 +966,14 @@ class DnfModule(YumDnf):
def _update_only(self, pkgs):
not_installed = []
for pkg in pkgs:
- if self._is_installed(pkg):
+ if self._is_installed(
+ self._package_dict(pkg)["nevra"] if isinstance(pkg, dnf.package.Package) else pkg
+ ):
try:
- if isinstance(to_text(pkg), text_type):
- self.base.upgrade(pkg)
- else:
+ if isinstance(pkg, dnf.package.Package):
self.base.package_upgrade(pkg)
+ else:
+ self.base.upgrade(pkg)
except Exception as e:
self.module.fail_json(
msg="Error occurred attempting update_only operation: {0}".format(to_native(e)),
@@ -1447,6 +1461,7 @@ def main():
# backported to yum because yum is now in "maintenance mode" upstream
yumdnf_argument_spec['argument_spec']['allowerasing'] = dict(default=False, type='bool')
yumdnf_argument_spec['argument_spec']['nobest'] = dict(default=False, type='bool')
+ yumdnf_argument_spec['argument_spec']['use_backend'] = dict(default='auto', choices=['auto', 'dnf4', 'dnf5'])
module = AnsibleModule(
**yumdnf_argument_spec