mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
commit
dc5c430f45
1 changed files with 17 additions and 15 deletions
|
@ -143,28 +143,30 @@ def enforce_state(module, params):
|
||||||
key = params["key"]
|
key = params["key"]
|
||||||
state = params.get("state", "present")
|
state = params.get("state", "present")
|
||||||
|
|
||||||
if '\n' in key:
|
key = key.split('\n')
|
||||||
module.fail_json(msg="key= can only contain a single key")
|
|
||||||
|
|
||||||
# check current state -- just get the filename, don't create file
|
# check current state -- just get the filename, don't create file
|
||||||
params["keyfile"] = keyfile(module, user, write=False)
|
params["keyfile"] = keyfile(module, user, write=False)
|
||||||
keys = readkeys(params["keyfile"])
|
keys = readkeys(params["keyfile"])
|
||||||
present = key in keys
|
|
||||||
|
|
||||||
# handle idempotent state=present
|
# Check our new keys, if any of them exist we'll continue.
|
||||||
if state=="present":
|
for new_key in key:
|
||||||
if present:
|
present = new_key in keys
|
||||||
module.exit_json(changed=False)
|
# handle idempotent state=present
|
||||||
keys.append(key)
|
if state=="present":
|
||||||
writekeys(module, keyfile(module, user,write=True), keys)
|
if present:
|
||||||
|
continue
|
||||||
|
keys.append(new_key)
|
||||||
|
writekeys(module, keyfile(module, user,write=True), keys)
|
||||||
|
params['changed'] = True
|
||||||
|
|
||||||
elif state=="absent":
|
elif state=="absent":
|
||||||
if not present:
|
if not present:
|
||||||
module.exit_json(changed=False)
|
continue
|
||||||
keys.remove(key)
|
keys.remove(new_key)
|
||||||
writekeys(module, keyfile(module, user,write=True), keys)
|
writekeys(module, keyfile(module, user,write=True), keys)
|
||||||
|
params['changed'] = True
|
||||||
|
|
||||||
params['changed'] = True
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue