dnf allowerasing (#48319)

Add the ability to pass allowerasing to alter the dnf transaction
behavior.

Fixes #24161

This is effectively a port of the original pull request from
poettler-ric who has since abandoned the PR

    https://github.com/ansible/ansible/pull/34111

Signed-off-by: Adam Miller <admiller@redhat.com>
pull/69259/head
Adam Miller 5 years ago committed by GitHub
parent 1c5c89baa6
commit dba17aeb13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
minor_changes:
- "dnf param to pass allowerasing"

@ -196,6 +196,13 @@ options:
- Has an effect only if I(download_only) is specified.
type: str
version_added: "2.8"
allowerasing:
description:
- If C(yes) it allows erasing of installed packages to resolve dependencies.
required: false
type: bool
default: "no"
version_added: "2.10"
notes:
- When used with a `loop:` each package will be processed individually, it is much more efficient to pass the list directly to the `name` option.
- Group removal doesn't work if the group was installed with Ansible because
@ -325,6 +332,9 @@ class DnfModule(YumDnf):
except AttributeError:
self.with_modules = False
# DNF specific args that are not part of YumDnf
self.allowerasing = self.module.params['allowerasing']
def is_lockfile_pid_valid(self):
# FIXME? it looks like DNF takes care of invalid lock files itself?
# https://github.com/ansible/ansible/issues/57189
@ -866,7 +876,6 @@ class DnfModule(YumDnf):
return False # seems like a sane default
def ensure(self):
allow_erasing = False
response = {
'msg': "",
@ -1119,13 +1128,13 @@ class DnfModule(YumDnf):
# Like the dnf CLI we want to allow recursive removal of dependent
# packages
allow_erasing = True
self.allowerasing = True
if self.autoremove:
self.base.autoremove()
try:
if not self.base.resolve(allow_erasing=allow_erasing):
if not self.base.resolve(allow_erasing=self.allowerasing):
if failure_response['failures']:
failure_response['msg'] = 'Failed to install some of the specified packages'
self.module.fail_json(**failure_response)
@ -1258,6 +1267,10 @@ def main():
# list=repos
# list=pkgspec
# Extend yumdnf_argument_spec with dnf-specific features that will never be
# backported to yum because yum is now in "maintenance mode" upstream
yumdnf_argument_spec['argument_spec']['allowerasing'] = dict(default=False, type='bool')
module = AnsibleModule(
**yumdnf_argument_spec
)

Loading…
Cancel
Save