Fixup previous apt_key patch to enable file based modes to work.

This commit is contained in:
Michael DeHaan 2013-06-26 14:46:29 -04:00
parent d9eca9182e
commit f3093cbb1a

View file

@ -129,9 +129,13 @@ def download_key(module, url):
module.fail_json(msg="error getting key id from url", traceback=format_exc()) module.fail_json(msg="error getting key id from url", traceback=format_exc())
def add_key(module, key): def add_key(module, keyfile, data=None):
cmd = "apt-key add -" if data is not None:
(rc, out, err) = module.run_command(cmd, data=key, check_rc=True, binary_data=True) cmd = "apt-key add -"
(rc, out, err) = module.run_command(cmd, data=data, check_rc=True, binary_data=True)
else:
cmd = "apt-key add %s" % (keyfile)
(rc, out, err) = module.run_command(cmd, check_rc=True)
return True return True
def remove_key(module, key_id): def remove_key(module, key_id):
@ -156,7 +160,7 @@ def main():
key_id = module.params['id'] key_id = module.params['id']
url = module.params['url'] url = module.params['url']
data = module.params['data'] data = module.params['data']
file = module.params['file'] filename = module.params['file']
state = module.params['state'] state = module.params['state']
changed = False changed = False
@ -170,14 +174,17 @@ def main():
if key_id and key_id in keys: if key_id and key_id in keys:
module.exit_json(changed=False) module.exit_json(changed=False)
else: else:
if not file and not data: if not filename and not data:
data = download_key(module, url) data = download_key(module, url)
if key_id and key_id in keys: if key_id and key_id in keys:
module.exit_json(changed=False) module.exit_json(changed=False)
else: else:
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=True)
add_key(module, (file if file else "-"), data) if filename:
add_key(module, filename)
else:
add_key(module, "-", data)
changed=False changed=False
keys2 = all_keys(module) keys2 = all_keys(module)
if len(keys) != len(keys2): if len(keys) != len(keys2):