mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
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:
parent
a48532de5f
commit
2610b521bc
3 changed files with 97 additions and 39 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue