* Added support for multi-line key files.

reviewable/pr18780/r1
Piffey Parlance 12 years ago
parent 46d0ba335c
commit cd55d3b6ab

@ -143,28 +143,32 @@ def enforce_state(module, params):
key = params["key"] key = params["key"]
state = params.get("state", "present") state = params.get("state", "present")
# If multiple keys split on the newline
if '\n' in key: if '\n' in key:
module.fail_json(msg="key= can only contain a single key") new_keys = key.split('\n')
# 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 new_keys:
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