Merge pull request #1970 from piffey/devel

Devel
reviewable/pr18780/r1
Michael DeHaan 12 years ago
commit 29ccc736e8

@ -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
# Check our new keys, if any of them exist we'll continue.
# handle idempotent state=present for new_key in key:
if state=="present": present = new_key in keys
if present: # handle idempotent state=present
module.exit_json(changed=False) if state=="present":
keys.append(key) if present:
writekeys(module, keyfile(module, user,write=True), keys) continue
keys.append(new_key)
elif state=="absent": writekeys(module, keyfile(module, user,write=True), keys)
if not present: params['changed'] = True
module.exit_json(changed=False)
keys.remove(key) elif state=="absent":
writekeys(module, keyfile(module, user,write=True), keys) if not present:
continue
params['changed'] = True keys.remove(new_key)
writekeys(module, keyfile(module, user,write=True), keys)
params['changed'] = True
return params return params
def main(): def main():

Loading…
Cancel
Save