From 1284bfd7426b117c165270a71f95dbc78a5a72ca Mon Sep 17 00:00:00 2001 From: Veeti Paananen Date: Fri, 14 Jun 2013 14:26:36 +0300 Subject: [PATCH 1/2] Add a file argument to apt_key --- library/packaging/apt_key | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/library/packaging/apt_key b/library/packaging/apt_key index de4ada8c39..831d49a0b1 100644 --- a/library/packaging/apt_key +++ b/library/packaging/apt_key @@ -37,6 +37,11 @@ options: default: none description: - identifier of key + file: + required: false + default: none + description: + - keyfile path url: required: false default: none @@ -110,9 +115,9 @@ def download_key(module, url): module.fail_json(msg="error getting key id from url", traceback=format_exc()) -def add_key(module, key): - cmd = "apt-key add -" - (rc, out, err) = module.run_command(cmd, data=key, check_rc=True) +def add_key(module, key, data=None): + cmd = "apt-key add %s" % (key) + (rc, out, err) = module.run_command(cmd, data=data, check_rc=True) return True def remove_key(module, key_id): @@ -127,6 +132,7 @@ def main(): id=dict(required=False, default=None), url=dict(required=False), data=dict(required=False), + file=dict(required=False), key=dict(required=False), state=dict(required=False, choices=['present', 'absent'], default='present') ), @@ -136,6 +142,7 @@ def main(): key_id = module.params['id'] url = module.params['url'] data = module.params['data'] + file = module.params['file'] state = module.params['state'] changed = False @@ -149,14 +156,14 @@ def main(): if key_id and key_id in keys: module.exit_json(changed=False) else: - if not data: + if not file and not data: data = download_key(module, url) if key_id and key_id in keys: module.exit_json(changed=False) else: if module.check_mode: module.exit_json(changed=True) - add_key(module, data) + add_key(module, (file if file else "-"), data) changed=False keys2 = all_keys(module) if len(keys) != len(keys2): From 77159d21da40f6fcb0bfdcb1886f57acf68ea4f4 Mon Sep 17 00:00:00 2001 From: Veeti Paananen Date: Mon, 17 Jun 2013 18:23:40 +0300 Subject: [PATCH 2/2] Add apt_key examples for file and data --- library/packaging/apt_key | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/packaging/apt_key b/library/packaging/apt_key index 831d49a0b1..73131e2484 100644 --- a/library/packaging/apt_key +++ b/library/packaging/apt_key @@ -58,6 +58,10 @@ examples: description: Add an Apt signing key, uses whichever key is at the URL - code: "apt_key: id=473041FA url=https://ftp-master.debian.org/keys/archive-key-6.0.asc state=present" description: Add an Apt signing key, will not download if present + - code: "apt_key: file=/tmp/apt.gpg state=present" + description: Add an Apt signing key from the specified file + - code: "apt_key: data='{{ lookup('file', 'apt.gpg') }}' state=present" + description: Add an Apt signing key from a local file - code: "apt_key: url=https://ftp-master.debian.org/keys/archive-key-6.0.asc state=absent" description: Remove an Apt signing key, uses whichever key is at the URL - code: "apt_key: id=473041FA state=absent"