Add a file argument to apt_key

This commit is contained in:
Veeti Paananen 2013-06-14 14:26:36 +03:00
parent cf2ddb6f80
commit 1284bfd742

View file

@ -37,6 +37,11 @@ options:
default: none default: none
description: description:
- identifier of key - identifier of key
file:
required: false
default: none
description:
- keyfile path
url: url:
required: false required: false
default: none default: none
@ -110,9 +115,9 @@ 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, key, data=None):
cmd = "apt-key add -" cmd = "apt-key add %s" % (key)
(rc, out, err) = module.run_command(cmd, data=key, check_rc=True) (rc, out, err) = module.run_command(cmd, data=data, check_rc=True)
return True return True
def remove_key(module, key_id): def remove_key(module, key_id):
@ -127,6 +132,7 @@ def main():
id=dict(required=False, default=None), id=dict(required=False, default=None),
url=dict(required=False), url=dict(required=False),
data=dict(required=False), data=dict(required=False),
file=dict(required=False),
key=dict(required=False), key=dict(required=False),
state=dict(required=False, choices=['present', 'absent'], default='present') state=dict(required=False, choices=['present', 'absent'], default='present')
), ),
@ -136,6 +142,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']
state = module.params['state'] state = module.params['state']
changed = False changed = False
@ -149,14 +156,14 @@ 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 data: if not file 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, data) add_key(module, (file if file else "-"), data)
changed=False changed=False
keys2 = all_keys(module) keys2 = all_keys(module)
if len(keys) != len(keys2): if len(keys) != len(keys2):