Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnf allowerasing #48319

Merged
merged 10 commits into from
Apr 30, 2020
3 changes: 3 additions & 0 deletions changelogs/fragments/dnf-allowerasing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "dnf param to pass allowerasing"
19 changes: 16 additions & 3 deletions lib/ansible/modules/packaging/os/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@
- 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
Expand Down Expand Up @@ -329,6 +336,9 @@ def __init__(self, module):
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
Expand Down Expand Up @@ -900,7 +910,6 @@ def _is_module_installed(self, module_spec):
return False # seems like a sane default

def ensure(self):
allow_erasing = False

response = {
'msg': "",
Expand Down Expand Up @@ -1149,13 +1158,13 @@ def ensure(self):

# 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)
Expand Down Expand Up @@ -1288,6 +1297,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
)
Expand Down