From 650b5fedb13968b3ca4220713afba72f4f943ef5 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 25 May 2017 21:19:20 +0530 Subject: [PATCH] Handle None and Blank value for sysctl module (#24871) Fix adds check for values provided by user for name and value in sysctl module. While providing name and value as in-line params, check for blank values Fixes #20176 Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/system/sysctl.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/sysctl.py b/lib/ansible/modules/system/sysctl.py index 98826c5eb31..e2a88c89f28 100644 --- a/lib/ansible/modules/system/sysctl.py +++ b/lib/ansible/modules/system/sysctl.py @@ -386,9 +386,21 @@ def main(): ignoreerrors = dict(default=False, type='bool'), sysctl_file = dict(default='/etc/sysctl.conf', type='path') ), - supports_check_mode=True + supports_check_mode=True, + required_if=[('state', 'present', ['value'])], ) + if module.params['name'] is None: + module.fail_json(msg="name can not be None") + if module.params['state'] == 'present' and module.params['value'] is None: + module.fail_json(msg="value can not be None") + + # In case of in-line params + if module.params['name'] == '': + module.fail_json(msg="name can not be blank") + if module.params['state'] == 'present' and module.params['value'] == '': + module.fail_json(msg="value can not be blank") + result = SysctlModule(module) module.exit_json(changed=result.changed)