diff options
author | Adam Miller <admiller@redhat.com> | 2018-11-05 15:00:42 -0600 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2018-11-05 16:00:42 -0500 |
commit | 1c777976c5134f310a97609da12776fc08551271 (patch) | |
tree | c67e9030817bd0c3d8eeaf0ce6dec15812589e9e /lib/ansible/module_utils/yumdnf.py | |
parent | 14037443dee3538b37aabf68c0486fc0fef5b43f (diff) | |
download | ansible-1c777976c5134f310a97609da12776fc08551271.tar.gz |
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>
Diffstat (limited to 'lib/ansible/module_utils/yumdnf.py')
-rw-r--r-- | lib/ansible/module_utils/yumdnf.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index a158e89157..7f5e550093 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -40,7 +40,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), @@ -104,6 +104,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=[], + ) + # This should really be redefined by both the yum and dnf module but a # default isn't a bad idea self.lockfile = '/var/run/yum.pid' |