Correct yum and dnf autoremove behavior (#47902)
* Correct yum and dnf autoremove behavior
Sanity check args passed to autoremove
Fixes #47184
Signed-off-by: Adam Miller <admiller@redhat.com>
* fix docs
Signed-off-by: Adam Miller <admiller@redhat.com>
(cherry picked from commit 1c777976c5
)
This commit is contained in:
parent
bab062d639
commit
3a14fe35e9
4 changed files with 21 additions and 8 deletions
3
changelogs/fragments/yumdnf-autoremove.yaml
Normal file
3
changelogs/fragments/yumdnf-autoremove.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
minor_changes:
|
||||
- "fix yum and dnf autoremove input sanitization to properly warn user if invalid options passed and update documentation to match"
|
|
@ -38,7 +38,7 @@ yumdnf_argument_spec = dict(
|
|||
security=dict(type='bool', default=False),
|
||||
skip_broken=dict(type='bool', default=False),
|
||||
# removed==absent, installed==present, these are accepted as aliases
|
||||
state=dict(type='str', default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
||||
state=dict(type='str', default=None, choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
||||
update_cache=dict(type='bool', default=False, aliases=['expire-cache']),
|
||||
update_only=dict(required=False, default="no", type='bool'),
|
||||
validate_certs=dict(type='bool', default=True),
|
||||
|
@ -101,6 +101,19 @@ class YumDnf(with_metaclass(ABCMeta, object)):
|
|||
'string of packages or a list of packages.'
|
||||
)
|
||||
|
||||
# Sanity checking for autoremove
|
||||
if self.state is None:
|
||||
if self.autoremove:
|
||||
self.state = "absent"
|
||||
else:
|
||||
self.state = "present"
|
||||
|
||||
if self.autoremove and (self.state != "absent"):
|
||||
self.module.fail_json(
|
||||
msg="Autoremove should be used alone or with state=absent",
|
||||
results=[],
|
||||
)
|
||||
|
||||
def listify_comma_sep_strings_in_list(self, some_list):
|
||||
"""
|
||||
method to accept a list of strings as the parameter, find any strings
|
||||
|
|
|
@ -41,8 +41,9 @@ options:
|
|||
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.
|
||||
choices: ['absent', 'present', 'installed', 'removed', 'latest']
|
||||
default: "present"
|
||||
|
||||
enablerepo:
|
||||
description:
|
||||
|
@ -1017,11 +1018,6 @@ class DnfModule(YumDnf):
|
|||
msg="Autoremove requires dnf>=2.0.1. Current dnf version is %s" % dnf.__version__,
|
||||
results=[],
|
||||
)
|
||||
if self.state not in ["absent", None]:
|
||||
self.module.fail_json(
|
||||
msg="Autoremove should be used alone or with state=absent",
|
||||
results=[],
|
||||
)
|
||||
|
||||
# Set state as installed by default
|
||||
# This is not set in AnsibleModule() because the following shouldn't happend
|
||||
|
|
|
@ -56,8 +56,9 @@ options:
|
|||
- C(present) and C(installed) will simply ensure that a desired package is installed.
|
||||
- C(latest) will update the specified package if it's not of the latest available version.
|
||||
- C(absent) and C(removed) will remove the specified 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.
|
||||
choices: [ absent, installed, latest, present, removed ]
|
||||
default: present
|
||||
enablerepo:
|
||||
description:
|
||||
- I(Repoid) of repositories to enable for the install/update operation.
|
||||
|
|
Loading…
Reference in a new issue