Remove sysctl entries when state=absent (#31486)

* Remove sysctl entry when state=absent
* Cleanup sysctl integration test syntax
* Correct grammar on error message
* Add sysctl integration test for state=absent
This commit is contained in:
Sam Doran 2017-10-10 12:01:33 -04:00 committed by Toshio Kuratomi
commit 2610b521bc
3 changed files with 97 additions and 39 deletions

View file

@ -165,6 +165,9 @@ class SysctlModule(object):
self.write_file = True
elif self.file_values[thisname] is None and self.args['state'] == "absent":
self.changed = False
elif self.file_values[thisname] and self.args['state'] == "absent":
self.changed = True
self.write_file = True
elif self.file_values[thisname] != self.args['value']:
self.changed = True
self.write_file = True
@ -380,20 +383,20 @@ def main():
)
if module.params['name'] is None:
module.fail_json(msg="name can not be None")
module.fail_json(msg="name cannot be None")
if module.params['state'] == 'present' and module.params['value'] is None:
module.fail_json(msg="value can not be None")
module.fail_json(msg="value cannot be None")
# In case of in-line params
if module.params['name'] == '':
module.fail_json(msg="name can not be blank")
module.fail_json(msg="name cannot be blank")
if module.params['state'] == 'present' and module.params['value'] == '':
module.fail_json(msg="value can not be blank")
module.fail_json(msg="value cannot be blank")
result = SysctlModule(module)
module.exit_json(changed=result.changed)
# import module snippets
if __name__ == '__main__':
main()