From 068cb9af59f2056a959a48d0e5b5f1fe033c3e9f Mon Sep 17 00:00:00 2001 From: Kesten Broughton Date: Fri, 2 May 2014 11:09:54 -0500 Subject: [PATCH] if key name already exists on tenant, check if public_key is offered that it matches the existing key --- cloud/nova_keypair | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloud/nova_keypair b/cloud/nova_keypair index 18674a1220a..b557b6db5f4 100644 --- a/cloud/nova_keypair +++ b/cloud/nova_keypair @@ -115,7 +115,10 @@ def main(): if module.params['state'] == 'present': for key in nova.keypairs.list(): if key.name == module.params['name']: - module.exit_json(changed = False, result = "Key present") + if module.params['public_key'] and (module.params['public_key'] != key.public_key ): + module.fail_json(msg = "name {} present but key hash not the same as offered. Delete key first.".format(key['name'])) + else: + module.exit_json(changed = False, result = "Key present") try: key = nova.keypairs.create(module.params['name'], module.params['public_key']) except Exception, e: